Cross-Validation


In [ ]:
from sklearn.datasets import load_digits

In [ ]:
digits = load_digits()
X = digits.data
y = digits.target

In [ ]:
from sklearn.cross_validation import cross_val_score
from sklearn.svm import LinearSVC

In [ ]:
cross_val_score(LinearSVC(), X, y)

In [ ]:
cross_val_score(LinearSVC(), X, y, cv=5, scoring="f1_macro")

Let's go to a binary task for a moment (even vs uneven)


In [ ]:
y % 2

In [ ]:
cross_val_score(LinearSVC(), X, y % 2, scoring="average_precision")

In [ ]:
cross_val_score(LinearSVC(), X, y % 2, scoring="roc_auc")

There are other ways to do cross-valiation


In [ ]:
from sklearn.cross_validation import ShuffleSplit
shuffle_split = ShuffleSplit(len(X), 10, test_size=.4)
cross_val_score(LinearSVC(), X, y, cv=shuffle_split)

In [ ]: