Warning: Declaration of action_plugin_tablewidth::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /s/bach/b/class/cs545/public_html/fall16/lib/plugins/tablewidth/action.php on line 93
===== Multi-class classification in scikit-learn =====
Let's use a One-vs-the-rest classifier on the [[https://archive.ics.uci.edu/ml/datasets/Iris | iris dataset]]. The data has four features that describe features of three types of iris flowers.
import numpy as np
from sklearn import datasets
from sklearn.multiclass import OneVsRestClassifier,OneVsOneClassifier
from sklearn.svm import LinearSVC,SVC
from sklearn import cross_validation
# load the iris dataset:
iris = datasets.load_iris()
X, y = iris.data, iris.target
# prepare cross validation folds
cv = cross_validation.StratifiedKFold(y, 5, shuffle=True, random_state=0)
# one-vs-the-rest
classifier = OneVsRestClassifier(LinearSVC())
print (np.mean(cross_validation.cross_val_score(classifier, X, y, cv=cv)))
# one-vs-one
classifier = OneVsOneClassifier(LinearSVC())
print (np.mean(cross_validation.cross_val_score(classifier, X, y, cv=cv)))
# does this mean that one-vs-one is better? not necessarily...
classifier = OneVsRestClassifier(SVC(C=1, kernel='rbf', gamma=0.5))
print (np.mean(cross_validation.cross_val_score(classifier, X, y, cv=cv)))