.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_exercises_plot_digits_classification_exercise.py: ================================ Digits Classification Exercise ================================ A tutorial exercise regarding the use of classification techniques on the Digits dataset. This exercise is used in the :ref:`clf_tut` part of the :ref:`supervised_learning_tut` section of the :ref:`stat_learn_tut_index`. .. rst-class:: sphx-glr-script-out Out: .. code-block:: none KNN score: 0.961111 LogisticRegression score: 0.933333 | .. code-block:: python print(__doc__) from sklearn import datasets, neighbors, linear_model digits = datasets.load_digits() X_digits = digits.data / digits.data.max() y_digits = digits.target n_samples = len(X_digits) X_train = X_digits[:int(.9 * n_samples)] y_train = y_digits[:int(.9 * n_samples)] X_test = X_digits[int(.9 * n_samples):] y_test = y_digits[int(.9 * n_samples):] knn = neighbors.KNeighborsClassifier() logistic = linear_model.LogisticRegression(solver='lbfgs', max_iter=1000, multi_class='multinomial') print('KNN score: %f' % knn.fit(X_train, y_train).score(X_test, y_test)) print('LogisticRegression score: %f' % logistic.fit(X_train, y_train).score(X_test, y_test)) **Total running time of the script:** ( 0 minutes 0.432 seconds) .. _sphx_glr_download_auto_examples_exercises_plot_digits_classification_exercise.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_digits_classification_exercise.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_digits_classification_exercise.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_