spce0038-machine-learning-w.../week1/slides/Lecture03_Scikit-Learn_Exercises_no_solutions.ipynb
2025-01-24 13:21:11 +00:00

1 line
2.7 KiB
Plaintext

{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# Exercises for Lecture 3 (Introduction to Scikit-Learn)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import datetime\n", "now = datetime.datetime.now()\n", "print(\"Last executed: \" + now.strftime(\"%Y-%m-%d %H:%M:%S\"))"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Load in example data for exercises."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from sklearn import datasets\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "slide"}}, "source": ["## Exercise 1: Classify hand-written digits "]}, {"cell_type": "markdown", "metadata": {}, "source": ["Consider the classification of hand-written digits."]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["First load example Scikit-Learn data."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from sklearn.datasets import load_digits\n", "digits = load_digits()"]}, {"cell_type": "markdown", "metadata": {}, "source": ["- Explore the data-set and plot some example images.\n", "- Split the data-set into training and test sets.\n", "- Train a logistic regression classifier, using a Newton Conjugate Gradient solver (`newton-cg`) with an $\\ell_2$ penalty (see [`LogisticRegression`](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) for further details).\n", "- Compute the accuracy of predictions on the test set."]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["### Plot example images"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["### Set up feature and target data"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["### Create training and test sets"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["### Choose model, instantiate, fit and predict"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["### Evaluate accuracy on test data"]}], "metadata": {"celltoolbar": "Tags", "kernelspec": {"display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.15"}}, "nbformat": 4, "nbformat_minor": 4}