분류 과제

scikit-learn으로 배우는 지도 학습

George Boorman

Core Curriculum Manager, DataCamp

미학습 데이터의 레이블 분류하기

  1. 모델을 구축합니다
  2. 모델은 우리가 전달하는 레이블이 지정된 데이터에서 학습합니다
  3. 레이블이 없는 데이터를 모델에 입력으로 전달합니다
  4. 모델은 미학습 데이터의 레이블을 예측합니다
  • 레이블된 데이터 = 학습 데이터
scikit-learn으로 배우는 지도 학습

k-최근접 이웃

  • 데이터 포인트의 레이블을 예측합니다

    • k개의 가장 가까운 레이블이 지정된 데이터 포인트 확인하기

    • 다수결 투표 적용

scikit-learn으로 배우는 지도 학습

k-최근접 이웃

scatter plot with observations in blue and red, and a new observation in black

scikit-learn으로 배우는 지도 학습

k-최근접 이웃

radius around the three observations nearest to the black dot

scikit-learn으로 배우는 지도 학습

k-최근접 이웃

radius around the five observations nearest to the black dot

scikit-learn으로 배우는 지도 학습

KNN 직관

scatterplot of total evening charge versus total day charge, where observations are colored in blue if they have churned and red if they have not churned

scikit-learn으로 배우는 지도 학습

KNN 직관

churn scatterplot with a decision boundary splitting observations by whether KNN predicts they will churn or not

scikit-learn으로 배우는 지도 학습

scikit-learn을 사용하여 분류기 학습하기

from sklearn.neighbors import KNeighborsClassifier

X = churn_df[["total_day_charge", "total_eve_charge"]].values y = churn_df["churn"].values
print(X.shape, y.shape)
(3333, 2), (3333,)
knn = KNeighborsClassifier(n_neighbors=15)

knn.fit(X, y)
scikit-learn으로 배우는 지도 학습

레이블이 없는 데이터 예측하기

X_new = np.array([[56.8, 17.5],
                  [24.4, 24.1],
                  [50.1, 10.9]])

print(X_new.shape)
(3, 2)
predictions = knn.predict(X_new)

print('Predictions: {}'.format(predictions))
Predictions: [1 0 0]
scikit-learn으로 배우는 지도 학습

연습해 봅시다!

scikit-learn으로 배우는 지도 학습

Preparing Video For Download...