Python/ML
[ML] KNN - KNeighborsClassifier
권멋져
2022. 8. 23. 21:58
KNeighborsClassifier
KNeighborsClassifier는 KNN 알고리즘으로 범주형 데이터를 예측할 때 사용한다.
KNeighborsRegressor와 사용법은 같다.
다만 성능을 판단할 때 Accuracy, Recall, Precision, f1-score로 판단한다.
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
x_train_s = scaler.fit_transform(x_train)
x_val_s = scaler.transform(x_val)
model = KNeighborsClassifier()
model.fit(x_train_s,y_train)
pred = model.predict(x_val_s)
print(classification_report(y_val,pred))
'''
precision recall f1-score support
0 0.86 0.96 0.91 300
1 0.52 0.24 0.33 59
accuracy 0.84 359
macro avg 0.69 0.60 0.62 359
weighted avg 0.81 0.84 0.81 359
'''