sklearn的简单使用

 1 import numpy as np
 2 from sklearn import datasets
 3 from sklearn.cross_validation import train_test_split
 4 from sklearn.neighbors import KNeighborsClassifier
 5 
 6 #数据载入
 7 iris = datasets.load_iris()
 8 iris_X = iris.data
 9 iris_y = iris.target
10 
11 #这里的这个打乱不仅仅是取testsize大小分开,而且还是把顺序打乱了
12 trainX,testX,trainY,testY = train_test_split(iris_X,iris_y,test_size = 0.3)
13 knn = KNeighborsClassifier()
14 
15 #训练
16 knn.fit(trainX,trainY)
17 #得到分类结果
18 print(knn.predict(testX))
19 print(testY)
20 #print (iris_y)
21 #print ((iris_X.shape))
View Code

 

import numpy as npfrom sklearn import datasetsfrom sklearn.cross_validation import train_test_splitfrom sklearn.neighbors import KNeighborsClassifier
iris = datasets.load_iris()iris_X = iris.datairis_y = iris.target
#这里的这个打乱不仅仅是取testsize大小分开,而且还是把顺序打乱了trainX,testX,trainY,testY = train_test_split(iris_X,iris_y,test_size = 0.3)knn = KNeighborsClassifier()knn.fit(trainX,trainY)print(knn.predict(testX))print(testY)#print (iris_y)#print ((iris_X.shape))

posted @ 2017-06-20 17:52  不说话的汤姆猫  阅读(265)  评论(0编辑  收藏  举报