Boston Crime Practice 🦹♀️🦹♂️
1. 문제 정의
- 보스턴 집값 데이터를 활용해서 집값을 예측해보자
- 회귀문제
**2. 데이터 수집**
from sklearn.datasets import fetch_openml
boston = fetch_openml('boston')
boston.keys()
import pandas as pd
X = pd.DataFrame(boston.data, columns = boston.feature_names)
y = pd.DataFrame(boston.target)
X.info()
X[['CHAS','RAD']] = X [['CHAS','RAD']].astype(int)
**3. 데이터 전저리**
from sklearn.preprocessing import StandardScaler
sds = StandardScaler()
sds.fit(X)
X_sds = sds.transform(X)
**5. 모델 선택 및 hyper parameter 튜닝**
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_sds,y, random_state =3)
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
**6. 학습**
lr.fit(X_train,y_train)
**7. 예측 및 평가**
from sklearn.model_selection import cross_val_score
cross_val_score(lr, X_train, y_train, cv = 5).mean()