1、数据处理
(1)原始数据
y_train=['male','male','male','male','famale','famale','famale','famale','famale']
[out]:
(2)LableBinarizer()的fit_transform()方法---将数据标签二值化
from sklearn.preprocessing import LabelBinarizer
lb=LabelBinarizer()
y_train_binarizer = lb.fit_transform(y_train)
[out]
(3)reshape(-1)------转数据转化为一行以用于实现K近邻算法
clf=KNeighborsClassifier(n_neighbors=K)
clf.fit(X_train,y_train_binarizer.reshape(-1))
[out]
(4)LableBinarizer()的inverse_transform()方法---将数据标签逆转还原成标签
predicted_label=lb.inverse_transform(prediction_binarized)
(5)KNeighborsClassifier()
KNN函数方法