This documentation is for scikit-learn version 0.11-gitOther versions

Citing

If you use the software, please consider citing scikit-learn.

This page

Python source code: plot_digits_classification_excercice.py

digits = datasets.load_digits()
X_digits = digits.data
y_digits = digits.target

n_samples = len(X_digits)

X_train = X_digits[:.9*n_samples]
y_train = y_digits[:.9*n_samples]
X_test = X_digits[.9*n_samples:]
y_test = y_digits[.9*n_samples:]

knn = neighbors.NeighborsClassifier()
logistic = linear_model.LogisticRegression()

print 'KNN score:', knn.fit(X_train, y_train).score(X_test, y_test)
print 'LogisticRegression score:', logistic.fit(X_train, y_train).score(X_test, y_test)