.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/exercises/plot_digits_classification_exercise.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via JupyterLite or Binder .. 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`. .. GENERATED FROM PYTHON SOURCE LINES 14-38 .. rst-class:: sphx-glr-script-out .. code-block:: none KNN score: 0.961111 LogisticRegression score: 0.933333 | .. code-block:: Python # Authors: The scikit-learn developers # SPDX-License-Identifier: BSD-3-Clause from sklearn import datasets, linear_model, neighbors X_digits, y_digits = datasets.load_digits(return_X_y=True) X_digits = X_digits / X_digits.max() n_samples = len(X_digits) X_train = X_digits[: int(0.9 * n_samples)] y_train = y_digits[: int(0.9 * n_samples)] X_test = X_digits[int(0.9 * n_samples) :] y_test = y_digits[int(0.9 * n_samples) :] knn = neighbors.KNeighborsClassifier() logistic = linear_model.LogisticRegression(max_iter=1000) 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) ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.067 seconds) .. _sphx_glr_download_auto_examples_exercises_plot_digits_classification_exercise.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/1.6.X?urlpath=lab/tree/notebooks/auto_examples/exercises/plot_digits_classification_exercise.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/exercises/plot_digits_classification_exercise.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_digits_classification_exercise.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_digits_classification_exercise.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_digits_classification_exercise.zip ` .. include:: plot_digits_classification_exercise.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_