{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 03: Linear and logistic regressions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The goal of this lab is to explore linear and logistic regression, implement them yourself and learn to use their respective scikit-learn implementation.\n", "\n", "Let us start by loading some of the usual librairies" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "import pandas as pd\n", "%pylab inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Linear regression\n", "\n", "We will now implement a linear regression, first using the closed form solution, and second with our gradient descent.\n", "\n", "## 1.1 Linear regression data\n", "\n", "Our first data set regards the quality ratings of a white _vinho verde_. Each wine is described by a number of physico-chemical descriptors such as acidity, sulfur dioxide content, density or pH." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | fixed acidity | \n", "volatile acidity | \n", "citric acid | \n", "residual sugar | \n", "chlorides | \n", "free sulfur dioxide | \n", "total sulfur dioxide | \n", "density | \n", "pH | \n", "sulphates | \n", "alcohol | \n", "quality | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "7.0 | \n", "0.27 | \n", "0.36 | \n", "20.7 | \n", "0.045 | \n", "45.0 | \n", "170.0 | \n", "1.0010 | \n", "3.00 | \n", "0.45 | \n", "8.8 | \n", "6 | \n", "
1 | \n", "6.3 | \n", "0.30 | \n", "0.34 | \n", "1.6 | \n", "0.049 | \n", "14.0 | \n", "132.0 | \n", "0.9940 | \n", "3.30 | \n", "0.49 | \n", "9.5 | \n", "6 | \n", "
2 | \n", "8.1 | \n", "0.28 | \n", "0.40 | \n", "6.9 | \n", "0.050 | \n", "30.0 | \n", "97.0 | \n", "0.9951 | \n", "3.26 | \n", "0.44 | \n", "10.1 | \n", "6 | \n", "
3 | \n", "7.2 | \n", "0.23 | \n", "0.32 | \n", "8.5 | \n", "0.058 | \n", "47.0 | \n", "186.0 | \n", "0.9956 | \n", "3.19 | \n", "0.40 | \n", "9.9 | \n", "6 | \n", "
4 | \n", "7.2 | \n", "0.23 | \n", "0.32 | \n", "8.5 | \n", "0.058 | \n", "47.0 | \n", "186.0 | \n", "0.9956 | \n", "3.19 | \n", "0.40 | \n", "9.9 | \n", "6 | \n", "