어떻게 프로젝트를 시작하게 되었고, 진행하면서 느낀 개발자와 디자이너의 생생한 스토리를 직접 확인해보세요!
Development
ML Chap 2. Machine Learning Project-1
#DS/ML/DL
HyeWon Lee
2023. 9. 18.
ML Chap 2. Machine Learning Project-1
Machine Learning Project(1)
Hands-on-Machine-Learning Chap2
실제 data 중 우리는 아래의 목표를 가지고 project를 진행했다.
California census data(block group마다 population, median income, median housing price 등)를 사용하여 California Median Housing Prices model 만들기
진행할 주요 단계는 아래와 같다.
the main step
Look at the big picture.
Get the data.
Discover and visualize the data to gain insights.
Prepare the data for Machine Learning algorithms.
Select a model and train it.
Fine-tune your model.
Present your solution.
Launch, monitor, and maintain your system.
1. Look at the big picture
1) Frame the problem
“모델을 어떻게 사용하려고 하는가?”
-> how you frame the problem, what algorithms you will select, what performance measure you will use to evaluate your model, how much effort you should spend tweaking it
해당 지역에 투자할 가치가 있는지 결정하는데 사용
“솔루션이 있다면 어떻게 구성되어 있는가?” -> 문제해결방법에 대한 정보, 참고 성능
현재 솔루션은 district housing prices을 전문가가 수동으로 추정. 한 팀이 구역에 관한 최신 정보를 모으고 있는데 median housing price을 얻을 수 없으면 복잡한 규칙 사용하여 추정. 이는 비용과 시간이 많이 들고 추정도 좋지 않음.
따라서 data를 기반으로 median housing price을 예측하는 모델을 훈련시키는 것이 유용하다 생각.
labeled training examples, 즉 median housing price을 가지고 있으므로 supervised learning task. 예측에 사용할 feature가 population, median income 등 다양하므로 multivariate regression. data에 연속적 흐름이 없고 데이터가 메모리에 들어갈 만큼 작으므로 batch.
2) Select a Performance Measure
회귀 문제의 대표적 성능 지표는 Root Mean Square Error(RMSE). 오차↑ RMSE↑
만약 outlier로 보이는 구역이 많으면 Mean Absolute Error(MAE) 사용
RMSE와 MAE 모두 the vector of predictions와 the vector of target values의 거리를 구하는 방식 -> 거리 측정에는 여러 norm이 있음(Euclidian norm, Manhattan norm)
norm의 지수가 클수록 큰 값의 원소에 치우치고 작은 값은 무시됨 -> RMSE가 MAE보다 outlier에 더 민감함. 하지만 outlier가 적으면 RMSE가 잘 맞아 일반적으로 RMSE가 잘 쓰임.
3) Check the Assumptions
prices를 있는 그대로의 값 자체로 사용할 것이라고 생각하여 regression을 할 계획을 세웠는데, 알고보니 저렴/보통/고가와 같은 카테고리를 사용한다면 지금까지 계획했던 regression이 아니라 classification을 사용해야 함. 그러므로 가정을 다시 한 번 확인해야 함.
2.Get the data.
1) Create the Workspace
2) Download the Data
import pandas as pdhousing=pd.read_csv('C:/Users/lhw29/OneDrive/바탕 화면/코딩 스터디/hands-on-machine-learning/housing.csv')
data snooping biaswhen estimating generalization error using the test set, the estimate will be too optimistic
test set은 일반적으로 data set의 20%로 한다.
프로그램을 다시 돌렸을 때 다른 test set이 생성되지 않도록 하는 방법
to save the test set on the first run and then load it in subsequent runs
to set the random number generator’s seed (e.g., np.ran dom.seed(42)) before calling np.random.permutation(), so that it always generates the same shuffled indices.
to use each instance’s identifier to decide whether or not it should go in the test set -> 일반적인 방법
a hash of each instance’s identifier를 계산하여 만약 the hash가 20% of the maximum hash value보다 작거나 같으면 instance를 test set에 넣는다. 이렇게 하면 여러 번 반복 실행되면서 data set이 갱신되더라도 test set이 동일하게 유지된다. 새로운 test set는 20% of the new instances를 포함하지만, 이전 training set에 있던 instance는 포함하지 않는다.
housing dataset에는 identifier column가 없다. 그러면 row index as the ID를 사용해서 해결한다.
the housing prices are very much related to the location(e.g., close to the ocean) and to the population density. -> useful to use a clustering algorithm
2) Looking for Correlations
data set이 너무 크지 않으면 모든 feature 간의 standard correlation coefficient를 corr() method로 계산할 수 있다.