Drkcore

08 06 2014 Python Tweet

scikit-learnで交差検定が地味に便利

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

ProductName 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 )


About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021