{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Matplotlib Linear Regression Animation in Jupyter Notebook\n", "\n", "This is a notebook for the medium article [Matplotlib Linear Regression Animation in Jupyter Notebook](https://bindichen.medium.com/matplotlib-linear-regression-animation-in-jupyter-notebook-2435b711bea2)\n", "\n", "Please check out article for instructions\n", "\n", "**License**: [BSD 2-Clause](https://opensource.org/licenses/BSD-2-Clause)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%%capture\n", "!conda install -c conda-forge -y ffmpeg pillow\n", "!pip install vega_datasets ipympl scikit-learn ffmpeg-python" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from sklearn.linear_model import LinearRegression\n", "from vega_datasets import data\n", "\n", "%matplotlib inline\n", "%config InlineBackend.figure_format = 'svg'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data Preprocessing" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Name | \n", "Miles_per_Gallon | \n", "Cylinders | \n", "Displacement | \n", "Horsepower | \n", "Weight_in_lbs | \n", "Acceleration | \n", "Year | \n", "Origin | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "chevrolet chevelle malibu | \n", "18.0 | \n", "8 | \n", "307.0 | \n", "130.0 | \n", "3504 | \n", "12.0 | \n", "1970-01-01 | \n", "USA | \n", "
1 | \n", "buick skylark 320 | \n", "15.0 | \n", "8 | \n", "350.0 | \n", "165.0 | \n", "3693 | \n", "11.5 | \n", "1970-01-01 | \n", "USA | \n", "
2 | \n", "plymouth satellite | \n", "18.0 | \n", "8 | \n", "318.0 | \n", "150.0 | \n", "3436 | \n", "11.0 | \n", "1970-01-01 | \n", "USA | \n", "
3 | \n", "amc rebel sst | \n", "16.0 | \n", "8 | \n", "304.0 | \n", "150.0 | \n", "3433 | \n", "12.0 | \n", "1970-01-01 | \n", "USA | \n", "
4 | \n", "ford torino | \n", "17.0 | \n", "8 | \n", "302.0 | \n", "140.0 | \n", "3449 | \n", "10.5 | \n", "1970-01-01 | \n", "USA | \n", "