Examples of scikit-learn documentation
阿新 • • 發佈:2017-12-11
nump nta code pos select k-fold python gpo cat
scikit-learn
Examples of scikit-learn documentation.
KFold K-折交叉驗證
>>> import numpy as np
>>> from sklearn.model_selection import KFold
>>> X = ["a", "b", "c", "d"]
>>> kf = KFold(n_splits=2)
>>> for train, test in kf.split(X):
... print("%s %s" % (train, test))
[2 3] [0 1]
[0 1] [2 3]
Reference : http://scikit-learn.org/stable/modules/cross_validation.html#k-fold
Decision Trees Classification 決策樹分類
>>> from sklearn import tree
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = tree.DecisionTreeClassifier()
>>> clf = clf.fit(X, Y)
>>> clf.predict([[2., 2.]])
array([1])
Reference : http://scikit-learn.org/stable/modules/tree.html#classification
Leave One Out 留一法
>>> from sklearn.model_selection import LeaveOneOut
>>> X = [1, 2, 3, 4]
>>> loo = LeaveOneOut()
>>> for train, test in loo.split(X):
... print ("%s %s" % (train, test))
[1 2 3] [0]
[0 2 3] [1]
[0 1 3] [2]
[0 1 2] [3]
Reference : http://scikit-learn.org/stable/modules/cross_validation.html#leave-one-out-loo
Examples of scikit-learn documentation