train_test_splitっていうメソッドが便利。これでテストデータと訓練データを分けてくれる。
SVC with linear kernelでちょっと検定
>>> import numpy as np >>> from sklearn import cross_validation >>> from sklearn import datasets >>> from sklearn import svm >>> iris = datasets.load_iris() >>> X_train, X_test, y_train, y_test = cross_validation.train_test_split( ... iris.data, iris.target, test_size=0.4, random_state=0) >>> X_train.shape, y_train.shape ((90, 4), (90,)) >>> X_test.shape, y_test.shape ((60, 4), (60,)) >>> clf = svm.SVC(kernel='linear').fit(X_train, y_train) >>> clf.score(X_test, y_test) 0.96666666666666667
Learning Scikit-Learn: Machine Learning in Python: Experience the Benefits of Machine Learning Techniques by Applying Them to Read-World Problems Using Python and the Open S
Raul Garreta
Packt Publishing / 3296円 ( 2013-11-25 )
Raul Garreta
Packt Publishing / 3296円 ( 2013-11-25 )