一 先来一个程序再说
root@ubuntu:~/work#vi t1.py
from sklearn.datasets import load_iris
from sklearn.cross_validation import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn import metrics
iris= load_iris()
X= iris.data
y= iris.target
for i in xrange(1,5):
print "random_state is ",i,", and accuracy score is:"
X_train, X_test, y_train, y_test =train_test_split(X, y,test_size=0.2, random_state=i)
knn = KNeighborsClassifier(n_neighbors=5)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
print metrics.accuracy_score(y_test,y_pred)
~
~
~
~
~
"t1.py"22L, 585C written
root@ubuntu:~/work#python t1.py
/usr/local/lib/python2.7/dist-packages/sklearn/cross_validation.py:44:DeprecationWarning: This module was deprecated in version 0.18 in favor of themodel_selection module into which all the refactored classes and functions aremoved. Also note that the interface of the new CV iterators are different fromthat of this module. This module will be removed in 0.20.