{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "# Lab 9: Regression" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "In the previous lab, you learned to make scatterplots and compute correlation\n", "coefficients. This supplement will show you how to fit lines to data and estimate confidence intervals for a regression.\n", "\n", "In this lab, as in Lab 8 on Correlation, you will study the correlation between head size (cubic centimeters) and brain weight (g) for a group of women. " ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "1. As usual, import pandas, Numpy and Seaborn. For regression, we'll also import sub-libraries to plot lines and calculate regression lines and correlation coefficients." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ "#TODO\n", "import pandas as pd\n", "import numpy as np\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt # Adds sub-library to plot line\n", "import scipy.stats as stats # Adds sub-library to calculate regression line and correlation coefficient" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "2. Using pandas, import the file `brainhead.csv` and view the resulting data frame. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | Head Size | \n", "Brain Weight | \n", "
---|---|---|
0 | \n", "2857 | \n", "1027 | \n", "
1 | \n", "3436 | \n", "1235 | \n", "
2 | \n", "3791 | \n", "1260 | \n", "
3 | \n", "3302 | \n", "1165 | \n", "
4 | \n", "3104 | \n", "1080 | \n", "
... | \n", "... | \n", "... | \n", "
98 | \n", "3214 | \n", "1110 | \n", "
99 | \n", "3394 | \n", "1215 | \n", "
100 | \n", "3233 | \n", "1104 | \n", "
101 | \n", "3352 | \n", "1170 | \n", "
102 | \n", "3391 | \n", "1120 | \n", "
103 rows × 2 columns
\n", "