{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import random\n", "\n", "import numpy as np\n", "import scipy as sp\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", "import statsmodels.api as sm\n", "import statsmodels.formula.api as smf\n", "\n", "sns.set_context(\"talk\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Anscombe's quartet\n", "\n", "Anscombe's quartet comprises of four datasets, and is rather famous. Why? You'll find out in this exercise." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
datasetxy
0I108.04
1I86.95
2I137.58
3I98.81
4I118.33
\n", "
" ], "text/plain": [ " dataset x y\n", "0 I 10 8.04\n", "1 I 8 6.95\n", "2 I 13 7.58\n", "3 I 9 8.81\n", "4 I 11 8.33" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "anascombe = pd.read_csv('data/anscombe.csv')\n", "anascombe.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 1\n", "\n", "For each of the four datasets...\n", " - Compute the mean and variance of both **x** and **y**\n", " - Compute the correlation coefficient between **x** and **y**\n", " - Compute the linear regression line: $y = \\beta_0 + \\beta_1 x + \\epsilon$ (hint: use statsmodels and look at the Statsmodels notebook)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# your code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 2\n", "\n", "Using Seaborn, visualize all four datasets. \n", "\n", "*hint: use sns.FacetGrid combined with plt.scatter*" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# your code here" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }