您好,登錄后才能下訂單哦!
如下所示:
from sklearn.datasets import load_iris iris = load_iris() print iris.data.shape from sklearn.cross_validation import train_test_split X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size = 0.25, random_state = 33) from sklearn.preprocessing import StandardScaler from sklearn.neighbors import KNeighborsClassifier ss = StandardScaler() X_train = ss.fit_transform(X_train) X_test = ss.transform(X_test) knc = KNeighborsClassifier() knc.fit(X_train, y_train) y_predict = knc.predict(X_test) print 'The accuracy of K-Nearest Neighbor Classifier is: ', knc.score(X_test, y_test) from sklearn.metrics import classification_report print classification_report(y_test, y_predict, target_names = iris.target_names)
以上這篇在python中利用KNN實現對iris進行分類的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。