1 line
2.4 KiB
Plaintext
1 line
2.4 KiB
Plaintext
{"cells": [{"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "slide"}}, "source": ["# Exercises for Lecture 6 (Training II)"]}, {"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": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# Common imports\n", "import os\n", "import numpy as np\n", "np.random.seed(42) # To make this notebook's output stable across runs\n", "\n", "# To plot pretty figures\n", "%matplotlib inline\n", "import matplotlib\n", "import matplotlib.pyplot as plt\n", "plt.rcParams['axes.labelsize'] = 14\n", "plt.rcParams['xtick.labelsize'] = 12\n", "plt.rcParams['ytick.labelsize'] = 12"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["## Set up training data "]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["m = 100\n", "X = 2 * np.random.rand(m, 1)\n", "y = 4 + 3 * X + np.random.randn(m, 1)\n", "plt.figure(figsize=(9,6))\n", "plt.plot(X, y, \"b.\")\n", "plt.xlabel(\"$x_1$\", fontsize=18)\n", "plt.ylabel(\"$y$\", rotation=0, fontsize=18)\n", "plt.axis([0, 2, 0, 15]);"]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["## Exercise 1: Solve using Scikit-Learn (without learning schedule)\n", "\n", "Solve the above problem using Scikit-Learn, considering a learning rate of 0.1. Display the intercept and slope of the fitted line."]}, {"cell_type": "markdown", "metadata": {"slideshow": {"slide_type": "subslide"}}, "source": ["## Exercise 2: Implement a mini-batch gradient descent algorithm to solve previous problem.\n", "\n", "Hints: \n", " - May want to start with stochastic GD implementation and adapt it. \n", " - The numpy function [`np.random.permutation`](https://numpy.org/doc/stable/reference/random/generated/numpy.random.permutation.html) may be useful."]}], "metadata": {"celltoolbar": "Tags", "kernelspec": {"display_name": "Python 3", "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.5"}}, "nbformat": 4, "nbformat_minor": 4} |