diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb
new file mode 100755
index 0000000..6cca015
--- /dev/null
+++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb
@@ -0,0 +1,1061 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Before your start:\n",
+ "- Read the README.md file\n",
+ "- Comment as much as you can and use the resources in the README.md file\n",
+ "- Happy learning!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import your libraries:\n",
+ "from sklearn import datasets\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 1 - Explore the Scikit-Learn Datasets\n",
+ "\n",
+ "Before starting to work on our own datasets, let's first explore the datasets that are included in this Python library. These datasets have been cleaned and formatted for use in ML algorithms."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "First, we will load the diabetes dataset. Do this in the cell below by importing the datasets and then loading the dataset to the `diabetes` variable using the `load_diabetes()` function."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'data': array([[ 0.03807591, 0.05068012, 0.06169621, ..., -0.00259226,\n",
+ " 0.01990842, -0.01764613],\n",
+ " [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338,\n",
+ " -0.06832974, -0.09220405],\n",
+ " [ 0.08529891, 0.05068012, 0.04445121, ..., -0.00259226,\n",
+ " 0.00286377, -0.02593034],\n",
+ " ...,\n",
+ " [ 0.04170844, 0.05068012, -0.01590626, ..., -0.01107952,\n",
+ " -0.04687948, 0.01549073],\n",
+ " [-0.04547248, -0.04464164, 0.03906215, ..., 0.02655962,\n",
+ " 0.04452837, -0.02593034],\n",
+ " [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338,\n",
+ " -0.00421986, 0.00306441]]),\n",
+ " 'target': array([151., 75., 141., 206., 135., 97., 138., 63., 110., 310., 101.,\n",
+ " 69., 179., 185., 118., 171., 166., 144., 97., 168., 68., 49.,\n",
+ " 68., 245., 184., 202., 137., 85., 131., 283., 129., 59., 341.,\n",
+ " 87., 65., 102., 265., 276., 252., 90., 100., 55., 61., 92.,\n",
+ " 259., 53., 190., 142., 75., 142., 155., 225., 59., 104., 182.,\n",
+ " 128., 52., 37., 170., 170., 61., 144., 52., 128., 71., 163.,\n",
+ " 150., 97., 160., 178., 48., 270., 202., 111., 85., 42., 170.,\n",
+ " 200., 252., 113., 143., 51., 52., 210., 65., 141., 55., 134.,\n",
+ " 42., 111., 98., 164., 48., 96., 90., 162., 150., 279., 92.,\n",
+ " 83., 128., 102., 302., 198., 95., 53., 134., 144., 232., 81.,\n",
+ " 104., 59., 246., 297., 258., 229., 275., 281., 179., 200., 200.,\n",
+ " 173., 180., 84., 121., 161., 99., 109., 115., 268., 274., 158.,\n",
+ " 107., 83., 103., 272., 85., 280., 336., 281., 118., 317., 235.,\n",
+ " 60., 174., 259., 178., 128., 96., 126., 288., 88., 292., 71.,\n",
+ " 197., 186., 25., 84., 96., 195., 53., 217., 172., 131., 214.,\n",
+ " 59., 70., 220., 268., 152., 47., 74., 295., 101., 151., 127.,\n",
+ " 237., 225., 81., 151., 107., 64., 138., 185., 265., 101., 137.,\n",
+ " 143., 141., 79., 292., 178., 91., 116., 86., 122., 72., 129.,\n",
+ " 142., 90., 158., 39., 196., 222., 277., 99., 196., 202., 155.,\n",
+ " 77., 191., 70., 73., 49., 65., 263., 248., 296., 214., 185.,\n",
+ " 78., 93., 252., 150., 77., 208., 77., 108., 160., 53., 220.,\n",
+ " 154., 259., 90., 246., 124., 67., 72., 257., 262., 275., 177.,\n",
+ " 71., 47., 187., 125., 78., 51., 258., 215., 303., 243., 91.,\n",
+ " 150., 310., 153., 346., 63., 89., 50., 39., 103., 308., 116.,\n",
+ " 145., 74., 45., 115., 264., 87., 202., 127., 182., 241., 66.,\n",
+ " 94., 283., 64., 102., 200., 265., 94., 230., 181., 156., 233.,\n",
+ " 60., 219., 80., 68., 332., 248., 84., 200., 55., 85., 89.,\n",
+ " 31., 129., 83., 275., 65., 198., 236., 253., 124., 44., 172.,\n",
+ " 114., 142., 109., 180., 144., 163., 147., 97., 220., 190., 109.,\n",
+ " 191., 122., 230., 242., 248., 249., 192., 131., 237., 78., 135.,\n",
+ " 244., 199., 270., 164., 72., 96., 306., 91., 214., 95., 216.,\n",
+ " 263., 178., 113., 200., 139., 139., 88., 148., 88., 243., 71.,\n",
+ " 77., 109., 272., 60., 54., 221., 90., 311., 281., 182., 321.,\n",
+ " 58., 262., 206., 233., 242., 123., 167., 63., 197., 71., 168.,\n",
+ " 140., 217., 121., 235., 245., 40., 52., 104., 132., 88., 69.,\n",
+ " 219., 72., 201., 110., 51., 277., 63., 118., 69., 273., 258.,\n",
+ " 43., 198., 242., 232., 175., 93., 168., 275., 293., 281., 72.,\n",
+ " 140., 189., 181., 209., 136., 261., 113., 131., 174., 257., 55.,\n",
+ " 84., 42., 146., 212., 233., 91., 111., 152., 120., 67., 310.,\n",
+ " 94., 183., 66., 173., 72., 49., 64., 48., 178., 104., 132.,\n",
+ " 220., 57.]),\n",
+ " 'frame': None,\n",
+ " 'DESCR': '.. _diabetes_dataset:\\n\\nDiabetes dataset\\n----------------\\n\\nTen baseline variables, age, sex, body mass index, average blood\\npressure, and six blood serum measurements were obtained for each of n =\\n442 diabetes patients, as well as the response of interest, a\\nquantitative measure of disease progression one year after baseline.\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 442\\n\\n :Number of Attributes: First 10 columns are numeric predictive values\\n\\n :Target: Column 11 is a quantitative measure of disease progression one year after baseline\\n\\n :Attribute Information:\\n - age age in years\\n - sex\\n - bmi body mass index\\n - bp average blood pressure\\n - s1 tc, total serum cholesterol\\n - s2 ldl, low-density lipoproteins\\n - s3 hdl, high-density lipoproteins\\n - s4 tch, total cholesterol / HDL\\n - s5 ltg, possibly log of serum triglycerides level\\n - s6 glu, blood sugar level\\n\\nNote: Each of these 10 feature variables have been mean centered and scaled by the standard deviation times `n_samples` (i.e. the sum of squares of each column totals 1).\\n\\nSource URL:\\nhttps://www4.stat.ncsu.edu/~boos/var.select/diabetes.html\\n\\nFor more information see:\\nBradley Efron, Trevor Hastie, Iain Johnstone and Robert Tibshirani (2004) \"Least Angle Regression,\" Annals of Statistics (with discussion), 407-499.\\n(https://web.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf)',\n",
+ " 'feature_names': ['age',\n",
+ " 'sex',\n",
+ " 'bmi',\n",
+ " 'bp',\n",
+ " 's1',\n",
+ " 's2',\n",
+ " 's3',\n",
+ " 's4',\n",
+ " 's5',\n",
+ " 's6'],\n",
+ " 'data_filename': '/Users/usuario/opt/anaconda3/envs/clase/lib/python3.8/site-packages/sklearn/datasets/data/diabetes_data.csv.gz',\n",
+ " 'target_filename': '/Users/usuario/opt/anaconda3/envs/clase/lib/python3.8/site-packages/sklearn/datasets/data/diabetes_target.csv.gz'}"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "diabetesdataset = datasets.load_diabetes()\n",
+ "diabetesdataset\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's explore this variable by looking at the different attributes. Do this by looking at the `keys()` of this variable."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "dict_keys(['data', 'target', 'frame', 'DESCR', 'feature_names', 'data_filename', 'target_filename'])"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "diabetesdataset.keys()\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The next step is to read the description of the dataset. Print the description in the cell below using the `DESCR` attribute of the `diabetes` variable"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'.. _diabetes_dataset:\\n\\nDiabetes dataset\\n----------------\\n\\nTen baseline variables, age, sex, body mass index, average blood\\npressure, and six blood serum measurements were obtained for each of n =\\n442 diabetes patients, as well as the response of interest, a\\nquantitative measure of disease progression one year after baseline.\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 442\\n\\n :Number of Attributes: First 10 columns are numeric predictive values\\n\\n :Target: Column 11 is a quantitative measure of disease progression one year after baseline\\n\\n :Attribute Information:\\n - age age in years\\n - sex\\n - bmi body mass index\\n - bp average blood pressure\\n - s1 tc, total serum cholesterol\\n - s2 ldl, low-density lipoproteins\\n - s3 hdl, high-density lipoproteins\\n - s4 tch, total cholesterol / HDL\\n - s5 ltg, possibly log of serum triglycerides level\\n - s6 glu, blood sugar level\\n\\nNote: Each of these 10 feature variables have been mean centered and scaled by the standard deviation times `n_samples` (i.e. the sum of squares of each column totals 1).\\n\\nSource URL:\\nhttps://www4.stat.ncsu.edu/~boos/var.select/diabetes.html\\n\\nFor more information see:\\nBradley Efron, Trevor Hastie, Iain Johnstone and Robert Tibshirani (2004) \"Least Angle Regression,\" Annals of Statistics (with discussion), 407-499.\\n(https://web.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf)'"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "diabetesdataset.DESCR"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "What are the variables in this dataset according to the description? List them in the markdown cell below"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### Enter your answer here:\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now explore the data. Scikit-learn typically takes in 2D numpy arrays as input (though pandas dataframes are also accepted). In the cell below find the shape of the numpy array contained in the data portion of the diabetes variable."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 0.03807591, 0.05068012, 0.06169621, ..., -0.00259226,\n",
+ " 0.01990842, -0.01764613],\n",
+ " [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338,\n",
+ " -0.06832974, -0.09220405],\n",
+ " [ 0.08529891, 0.05068012, 0.04445121, ..., -0.00259226,\n",
+ " 0.00286377, -0.02593034],\n",
+ " ...,\n",
+ " [ 0.04170844, 0.05068012, -0.01590626, ..., -0.01107952,\n",
+ " -0.04687948, 0.01549073],\n",
+ " [-0.04547248, -0.04464164, 0.03906215, ..., 0.02655962,\n",
+ " 0.04452837, -0.02593034],\n",
+ " [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338,\n",
+ " -0.00421986, 0.00306441]])"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "diabetesdataset.data\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 2 - Perform Supervised Learning on the Dataset"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### The data has already been split to predictor and response variables. The response variable is in the `target` portion of the variable. \n",
+ "\n",
+ "Given this information, let's apply what we have previously learned about linear regression and apply the algorithm to the diabetes dataset. In the cell below, import the linear regression class from sklearn. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([151., 75., 141., 206., 135., 97., 138., 63., 110., 310., 101.,\n",
+ " 69., 179., 185., 118., 171., 166., 144., 97., 168., 68., 49.,\n",
+ " 68., 245., 184., 202., 137., 85., 131., 283., 129., 59., 341.,\n",
+ " 87., 65., 102., 265., 276., 252., 90., 100., 55., 61., 92.,\n",
+ " 259., 53., 190., 142., 75., 142., 155., 225., 59., 104., 182.,\n",
+ " 128., 52., 37., 170., 170., 61., 144., 52., 128., 71., 163.,\n",
+ " 150., 97., 160., 178., 48., 270., 202., 111., 85., 42., 170.,\n",
+ " 200., 252., 113., 143., 51., 52., 210., 65., 141., 55., 134.,\n",
+ " 42., 111., 98., 164., 48., 96., 90., 162., 150., 279., 92.,\n",
+ " 83., 128., 102., 302., 198., 95., 53., 134., 144., 232., 81.,\n",
+ " 104., 59., 246., 297., 258., 229., 275., 281., 179., 200., 200.,\n",
+ " 173., 180., 84., 121., 161., 99., 109., 115., 268., 274., 158.,\n",
+ " 107., 83., 103., 272., 85., 280., 336., 281., 118., 317., 235.,\n",
+ " 60., 174., 259., 178., 128., 96., 126., 288., 88., 292., 71.,\n",
+ " 197., 186., 25., 84., 96., 195., 53., 217., 172., 131., 214.,\n",
+ " 59., 70., 220., 268., 152., 47., 74., 295., 101., 151., 127.,\n",
+ " 237., 225., 81., 151., 107., 64., 138., 185., 265., 101., 137.,\n",
+ " 143., 141., 79., 292., 178., 91., 116., 86., 122., 72., 129.,\n",
+ " 142., 90., 158., 39., 196., 222., 277., 99., 196., 202., 155.,\n",
+ " 77., 191., 70., 73., 49., 65., 263., 248., 296., 214., 185.,\n",
+ " 78., 93., 252., 150., 77., 208., 77., 108., 160., 53., 220.,\n",
+ " 154., 259., 90., 246., 124., 67., 72., 257., 262., 275., 177.,\n",
+ " 71., 47., 187., 125., 78., 51., 258., 215., 303., 243., 91.,\n",
+ " 150., 310., 153., 346., 63., 89., 50., 39., 103., 308., 116.,\n",
+ " 145., 74., 45., 115., 264., 87., 202., 127., 182., 241., 66.,\n",
+ " 94., 283., 64., 102., 200., 265., 94., 230., 181., 156., 233.,\n",
+ " 60., 219., 80., 68., 332., 248., 84., 200., 55., 85., 89.,\n",
+ " 31., 129., 83., 275., 65., 198., 236., 253., 124., 44., 172.,\n",
+ " 114., 142., 109., 180., 144., 163., 147., 97., 220., 190., 109.,\n",
+ " 191., 122., 230., 242., 248., 249., 192., 131., 237., 78., 135.,\n",
+ " 244., 199., 270., 164., 72., 96., 306., 91., 214., 95., 216.,\n",
+ " 263., 178., 113., 200., 139., 139., 88., 148., 88., 243., 71.,\n",
+ " 77., 109., 272., 60., 54., 221., 90., 311., 281., 182., 321.,\n",
+ " 58., 262., 206., 233., 242., 123., 167., 63., 197., 71., 168.,\n",
+ " 140., 217., 121., 235., 245., 40., 52., 104., 132., 88., 69.,\n",
+ " 219., 72., 201., 110., 51., 277., 63., 118., 69., 273., 258.,\n",
+ " 43., 198., 242., 232., 175., 93., 168., 275., 293., 281., 72.,\n",
+ " 140., 189., 181., 209., 136., 261., 113., 131., 174., 257., 55.,\n",
+ " 84., 42., 146., 212., 233., 91., 111., 152., 120., 67., 310.,\n",
+ " 94., 183., 66., 173., 72., 49., 64., 48., 178., 104., 132.,\n",
+ " 220., 57.])"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "diabetesdataset.target"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Initialize the model in the variable `diabetes_model`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "from sklearn.linear_model import LinearRegression"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "linreg=LinearRegression()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In the cell below, fit the model and print the intercept and coefficients of the model. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Bonus Challenge 1 - Conduct a Hypothesis Test on the Model\n",
+ "\n",
+ "Once we have generated a linear model, we can test each coefficient using a t-test to see whether the confidence interval for the variable contains zero. We can also perform an overall F test to check whether at least one coefficient is significantly different from zero. \n",
+ "\n",
+ "Refer to the resource in this [link](https://onlinecourses.science.psu.edu/stat501/node/297/) for more details and perform the t-tests for the model above. Additionally, interpret the results and list coefficients are significantly different from zero.\n",
+ "\n",
+ "\n",
+ "Hint: use the statsmodels package.\n",
+ "\n",
+ "Your result should look similar to this:\n",
+ "\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 2 - Peform Supervised Learning on a Pandas Dataframe"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now that we have looked at data that has been formatted for scikit-learn, let's look at data that we will need to format ourselves.\n",
+ "\n",
+ "In the next cell, load the `auto-mpg.csv` file included in this folder and assign it to a variable called `auto`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "import pandas as pd\n",
+ "auto = pd.read_csv('../auto-mpg.csv')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Look at the first 5 rows using the `head()` function:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " mpg | \n",
+ " cylinders | \n",
+ " displacement | \n",
+ " horse_power | \n",
+ " weight | \n",
+ " acceleration | \n",
+ " model_year | \n",
+ " car_name | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 18.0 | \n",
+ " 8 | \n",
+ " 307.0 | \n",
+ " 130.0 | \n",
+ " 3504 | \n",
+ " 12.0 | \n",
+ " 70 | \n",
+ " \\t\"chevrolet chevelle malibu\" | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 15.0 | \n",
+ " 8 | \n",
+ " 350.0 | \n",
+ " 165.0 | \n",
+ " 3693 | \n",
+ " 11.5 | \n",
+ " 70 | \n",
+ " \\t\"buick skylark 320\" | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 18.0 | \n",
+ " 8 | \n",
+ " 318.0 | \n",
+ " 150.0 | \n",
+ " 3436 | \n",
+ " 11.0 | \n",
+ " 70 | \n",
+ " \\t\"plymouth satellite\" | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 16.0 | \n",
+ " 8 | \n",
+ " 304.0 | \n",
+ " 150.0 | \n",
+ " 3433 | \n",
+ " 12.0 | \n",
+ " 70 | \n",
+ " \\t\"amc rebel sst\" | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 17.0 | \n",
+ " 8 | \n",
+ " 302.0 | \n",
+ " 140.0 | \n",
+ " 3449 | \n",
+ " 10.5 | \n",
+ " 70 | \n",
+ " \\t\"ford torino\" | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " mpg cylinders displacement horse_power weight acceleration \\\n",
+ "0 18.0 8 307.0 130.0 3504 12.0 \n",
+ "1 15.0 8 350.0 165.0 3693 11.5 \n",
+ "2 18.0 8 318.0 150.0 3436 11.0 \n",
+ "3 16.0 8 304.0 150.0 3433 12.0 \n",
+ "4 17.0 8 302.0 140.0 3449 10.5 \n",
+ "\n",
+ " model_year car_name \n",
+ "0 70 \\t\"chevrolet chevelle malibu\" \n",
+ "1 70 \\t\"buick skylark 320\" \n",
+ "2 70 \\t\"plymouth satellite\" \n",
+ "3 70 \\t\"amc rebel sst\" \n",
+ "4 70 \\t\"ford torino\" "
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "auto.head()\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Evaluate the data to ensure that all numeric columns are correctly detected as such by pandas. If a column is misclassified as object, coerce it to numeric."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "mpg float64\n",
+ "cylinders int64\n",
+ "displacement float64\n",
+ "horse_power float64\n",
+ "weight int64\n",
+ "acceleration float64\n",
+ "model_year int64\n",
+ "car_name object\n",
+ "dtype: object"
+ ]
+ },
+ "execution_count": 37,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "auto.dtypes"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "What is the newest model year and the oldest model year?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "70"
+ ]
+ },
+ "execution_count": 38,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "auto.model_year.max()\n",
+ "auto.model_year.min()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Check the dataset for missing values and remove all rows containing at least one missing value."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "horse_power 6\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "nan_cols=auto.isna().sum()\n",
+ "\n",
+ "nan_cols[nan_cols>0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "auto.dropna(inplace=True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Find the frequency table for the `cylinders` column using the `value_counts()` function. How many possible values of cylinders are there?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "4 199\n",
+ "8 103\n",
+ "6 83\n",
+ "3 4\n",
+ "5 3\n",
+ "Name: cylinders, dtype: int64"
+ ]
+ },
+ "execution_count": 41,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "auto.cylinders.value_counts()\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We would like to generate a linear regression model that will predict mpg. To do this, first drop the `car_name` column since it does not contain any quantitative data. Next separate the dataframe to predictor and response variables. Separate those into test and training data with 80% of the data in the training set and the remainder in the test set. \n",
+ "\n",
+ "Assign the predictor and response training data to `X_train` and `y_train` respectively. Similarly, assign the predictor and response test data to `X_test` and `y_test`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "auto.drop(columns= 'car_name', inplace=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "auto=auto.dropna(inplace=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "TypeError",
+ "evalue": "'NoneType' object is not subscriptable",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mauto\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'mpg'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mauto\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mauto\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;34m'mpg'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mTypeError\u001b[0m: 'NoneType' object is not subscriptable"
+ ]
+ }
+ ],
+ "source": [
+ "y=auto['mpg']\n",
+ "x=auto[[i for i in list(auto.columns) if i != 'mpg']]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from sklearn.model_selection import train_test_split\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'x' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx_test\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mtrain_test_split\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_size\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0;36m0.2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_test\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mtrain_test_split\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_size\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0;36m0.2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mNameError\u001b[0m: name 'x' is not defined"
+ ]
+ }
+ ],
+ "source": [
+ "x_train, x_test= train_test_split(x, test_size= 0.2)\n",
+ "y_train, y_test= train_test_split(y, test_size= 0.2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we will the dataset that we processed and peform linear regression on this data to predict the mpg for each vehicle. Initialize the model in the cell below."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "from sklearn.linear_model import LinearRegression as LinReg\n",
+ "linreg=LinReg()\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Next, fit the model in the cell below."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'x_train' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Your code here:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mlinreg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m: name 'x_train' is not defined"
+ ]
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "linreg.fit(x_train, y_train)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 3 - Evaluate the Model\n",
+ "\n",
+ "the r squared score of a model tells us how much variation is explained by the model. In a typical dataset, most observations differ from the mean. When we create a model, we are trying to generate an equation that will tell us by how much each observation will differ from the mean. Obviously, the vast majority of models are not perfect. They can only predict some of the variation from the mean but not all of it. We attribute the rest of the difference between the actual value and the mean to random error. We would like random error to explain the as little as possible of the variation. This is why the r squared score is an important metric.\n",
+ "\n",
+ "In the next cell, compute the r squared score of the model. Do this by first computing the predicted values and assign them to `y_pred`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import the necessary function:\n",
+ "from sklearn.metrics import r2_score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### Our next step is to evaluate the model using the test data. We would like to ensure that our model is not overfitting the data. This means that our model will not be able to generalize well outside of the training data.\n",
+ "\n",
+ "In the cell below, use the model to generate the predicted values for the training data and assign them to `y_test_pred`. Compute the r squared score for the test data by comparing the oberserved `y_test` data and the predicted `y_test_pred`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 4 - Improve the Model Fit\n",
+ "\n",
+ "While the most common way to improve the fit of a model is by using regularization, there are other simpler ways to improve model fit. The first is to create a simpler model. The second is to increase the train sample size.\n",
+ "\n",
+ "Let us start with the easier option and increase our train sample size to 90% of the data. Create a new test train split and name the new predictors and response variables `X_train09`, `X_test09`, `y_train09`, `y_test09`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Initialize a new model. Name this model `auto_model09`. Fit the model to the new sample data."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Compute the predicted values and r squared score for our new model and new sample data."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Compute the r squared score for the smaller test set. Is there an improvement in the test r squared?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Bonus Challenge 2 - Backward Elimination \n",
+ "\n",
+ "The main way to produce a simpler linear regression model is to reduce the number of variables used in the model. In scikit-learn, we can do this by using recursive feature elimination. You can read more about RFE [here](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.RFE.html).\n",
+ "\n",
+ "In the next cell, we will import RFE"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Follow the documentation and initialize an RFE model using the `auto_model` linear regression model. Set `n_features_to_select=3`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Fit the model and print the ranking"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Feature importance is ranked from most important (1) to least important (4). Generate a model with the three most important features. The features correspond to variable names. For example, feature 1 is `cylinders` and feature 2 is `displacement`.\n",
+ "\n",
+ "Perform a test-train split on this reduced column data and call the split data `X_train_reduced`, `X_test_reduced`, `y_test_reduced`, `y_train_reduced`. Use an 80% split."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Generate a new model called `auto_model_reduced` and fit this model. Then proceed to compute the r squared score for the model. Did this cause an improvement in the r squared score?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here: \n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "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": 2
+}
diff --git a/your-code/main.ipynb b/your-code/main.ipynb
index f6f69ed..6cca015 100755
--- a/your-code/main.ipynb
+++ b/your-code/main.ipynb
@@ -12,12 +12,12 @@
},
{
"cell_type": "code",
- "execution_count": 174,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Import your libraries:\n",
- "\n"
+ "from sklearn import datasets\n"
]
},
{
@@ -38,12 +38,91 @@
},
{
"cell_type": "code",
- "execution_count": 175,
- "metadata": {},
- "outputs": [],
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'data': array([[ 0.03807591, 0.05068012, 0.06169621, ..., -0.00259226,\n",
+ " 0.01990842, -0.01764613],\n",
+ " [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338,\n",
+ " -0.06832974, -0.09220405],\n",
+ " [ 0.08529891, 0.05068012, 0.04445121, ..., -0.00259226,\n",
+ " 0.00286377, -0.02593034],\n",
+ " ...,\n",
+ " [ 0.04170844, 0.05068012, -0.01590626, ..., -0.01107952,\n",
+ " -0.04687948, 0.01549073],\n",
+ " [-0.04547248, -0.04464164, 0.03906215, ..., 0.02655962,\n",
+ " 0.04452837, -0.02593034],\n",
+ " [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338,\n",
+ " -0.00421986, 0.00306441]]),\n",
+ " 'target': array([151., 75., 141., 206., 135., 97., 138., 63., 110., 310., 101.,\n",
+ " 69., 179., 185., 118., 171., 166., 144., 97., 168., 68., 49.,\n",
+ " 68., 245., 184., 202., 137., 85., 131., 283., 129., 59., 341.,\n",
+ " 87., 65., 102., 265., 276., 252., 90., 100., 55., 61., 92.,\n",
+ " 259., 53., 190., 142., 75., 142., 155., 225., 59., 104., 182.,\n",
+ " 128., 52., 37., 170., 170., 61., 144., 52., 128., 71., 163.,\n",
+ " 150., 97., 160., 178., 48., 270., 202., 111., 85., 42., 170.,\n",
+ " 200., 252., 113., 143., 51., 52., 210., 65., 141., 55., 134.,\n",
+ " 42., 111., 98., 164., 48., 96., 90., 162., 150., 279., 92.,\n",
+ " 83., 128., 102., 302., 198., 95., 53., 134., 144., 232., 81.,\n",
+ " 104., 59., 246., 297., 258., 229., 275., 281., 179., 200., 200.,\n",
+ " 173., 180., 84., 121., 161., 99., 109., 115., 268., 274., 158.,\n",
+ " 107., 83., 103., 272., 85., 280., 336., 281., 118., 317., 235.,\n",
+ " 60., 174., 259., 178., 128., 96., 126., 288., 88., 292., 71.,\n",
+ " 197., 186., 25., 84., 96., 195., 53., 217., 172., 131., 214.,\n",
+ " 59., 70., 220., 268., 152., 47., 74., 295., 101., 151., 127.,\n",
+ " 237., 225., 81., 151., 107., 64., 138., 185., 265., 101., 137.,\n",
+ " 143., 141., 79., 292., 178., 91., 116., 86., 122., 72., 129.,\n",
+ " 142., 90., 158., 39., 196., 222., 277., 99., 196., 202., 155.,\n",
+ " 77., 191., 70., 73., 49., 65., 263., 248., 296., 214., 185.,\n",
+ " 78., 93., 252., 150., 77., 208., 77., 108., 160., 53., 220.,\n",
+ " 154., 259., 90., 246., 124., 67., 72., 257., 262., 275., 177.,\n",
+ " 71., 47., 187., 125., 78., 51., 258., 215., 303., 243., 91.,\n",
+ " 150., 310., 153., 346., 63., 89., 50., 39., 103., 308., 116.,\n",
+ " 145., 74., 45., 115., 264., 87., 202., 127., 182., 241., 66.,\n",
+ " 94., 283., 64., 102., 200., 265., 94., 230., 181., 156., 233.,\n",
+ " 60., 219., 80., 68., 332., 248., 84., 200., 55., 85., 89.,\n",
+ " 31., 129., 83., 275., 65., 198., 236., 253., 124., 44., 172.,\n",
+ " 114., 142., 109., 180., 144., 163., 147., 97., 220., 190., 109.,\n",
+ " 191., 122., 230., 242., 248., 249., 192., 131., 237., 78., 135.,\n",
+ " 244., 199., 270., 164., 72., 96., 306., 91., 214., 95., 216.,\n",
+ " 263., 178., 113., 200., 139., 139., 88., 148., 88., 243., 71.,\n",
+ " 77., 109., 272., 60., 54., 221., 90., 311., 281., 182., 321.,\n",
+ " 58., 262., 206., 233., 242., 123., 167., 63., 197., 71., 168.,\n",
+ " 140., 217., 121., 235., 245., 40., 52., 104., 132., 88., 69.,\n",
+ " 219., 72., 201., 110., 51., 277., 63., 118., 69., 273., 258.,\n",
+ " 43., 198., 242., 232., 175., 93., 168., 275., 293., 281., 72.,\n",
+ " 140., 189., 181., 209., 136., 261., 113., 131., 174., 257., 55.,\n",
+ " 84., 42., 146., 212., 233., 91., 111., 152., 120., 67., 310.,\n",
+ " 94., 183., 66., 173., 72., 49., 64., 48., 178., 104., 132.,\n",
+ " 220., 57.]),\n",
+ " 'frame': None,\n",
+ " 'DESCR': '.. _diabetes_dataset:\\n\\nDiabetes dataset\\n----------------\\n\\nTen baseline variables, age, sex, body mass index, average blood\\npressure, and six blood serum measurements were obtained for each of n =\\n442 diabetes patients, as well as the response of interest, a\\nquantitative measure of disease progression one year after baseline.\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 442\\n\\n :Number of Attributes: First 10 columns are numeric predictive values\\n\\n :Target: Column 11 is a quantitative measure of disease progression one year after baseline\\n\\n :Attribute Information:\\n - age age in years\\n - sex\\n - bmi body mass index\\n - bp average blood pressure\\n - s1 tc, total serum cholesterol\\n - s2 ldl, low-density lipoproteins\\n - s3 hdl, high-density lipoproteins\\n - s4 tch, total cholesterol / HDL\\n - s5 ltg, possibly log of serum triglycerides level\\n - s6 glu, blood sugar level\\n\\nNote: Each of these 10 feature variables have been mean centered and scaled by the standard deviation times `n_samples` (i.e. the sum of squares of each column totals 1).\\n\\nSource URL:\\nhttps://www4.stat.ncsu.edu/~boos/var.select/diabetes.html\\n\\nFor more information see:\\nBradley Efron, Trevor Hastie, Iain Johnstone and Robert Tibshirani (2004) \"Least Angle Regression,\" Annals of Statistics (with discussion), 407-499.\\n(https://web.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf)',\n",
+ " 'feature_names': ['age',\n",
+ " 'sex',\n",
+ " 'bmi',\n",
+ " 'bp',\n",
+ " 's1',\n",
+ " 's2',\n",
+ " 's3',\n",
+ " 's4',\n",
+ " 's5',\n",
+ " 's6'],\n",
+ " 'data_filename': '/Users/usuario/opt/anaconda3/envs/clase/lib/python3.8/site-packages/sklearn/datasets/data/diabetes_data.csv.gz',\n",
+ " 'target_filename': '/Users/usuario/opt/anaconda3/envs/clase/lib/python3.8/site-packages/sklearn/datasets/data/diabetes_target.csv.gz'}"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "diabetesdataset = datasets.load_diabetes()\n",
+ "diabetesdataset\n"
]
},
{
@@ -55,11 +134,23 @@
},
{
"cell_type": "code",
- "execution_count": 176,
- "metadata": {},
- "outputs": [],
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "dict_keys(['data', 'target', 'frame', 'DESCR', 'feature_names', 'data_filename', 'target_filename'])"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
+ "diabetesdataset.keys()\n",
"\n"
]
},
@@ -72,11 +163,24 @@
},
{
"cell_type": "code",
- "execution_count": 177,
- "metadata": {},
- "outputs": [],
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'.. _diabetes_dataset:\\n\\nDiabetes dataset\\n----------------\\n\\nTen baseline variables, age, sex, body mass index, average blood\\npressure, and six blood serum measurements were obtained for each of n =\\n442 diabetes patients, as well as the response of interest, a\\nquantitative measure of disease progression one year after baseline.\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 442\\n\\n :Number of Attributes: First 10 columns are numeric predictive values\\n\\n :Target: Column 11 is a quantitative measure of disease progression one year after baseline\\n\\n :Attribute Information:\\n - age age in years\\n - sex\\n - bmi body mass index\\n - bp average blood pressure\\n - s1 tc, total serum cholesterol\\n - s2 ldl, low-density lipoproteins\\n - s3 hdl, high-density lipoproteins\\n - s4 tch, total cholesterol / HDL\\n - s5 ltg, possibly log of serum triglycerides level\\n - s6 glu, blood sugar level\\n\\nNote: Each of these 10 feature variables have been mean centered and scaled by the standard deviation times `n_samples` (i.e. the sum of squares of each column totals 1).\\n\\nSource URL:\\nhttps://www4.stat.ncsu.edu/~boos/var.select/diabetes.html\\n\\nFor more information see:\\nBradley Efron, Trevor Hastie, Iain Johnstone and Robert Tibshirani (2004) \"Least Angle Regression,\" Annals of Statistics (with discussion), 407-499.\\n(https://web.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf)'"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here:\n"
+ "# Your code here:\n",
+ "\n",
+ "diabetesdataset.DESCR"
]
},
{
@@ -104,12 +208,35 @@
},
{
"cell_type": "code",
- "execution_count": 178,
- "metadata": {},
- "outputs": [],
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 0.03807591, 0.05068012, 0.06169621, ..., -0.00259226,\n",
+ " 0.01990842, -0.01764613],\n",
+ " [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338,\n",
+ " -0.06832974, -0.09220405],\n",
+ " [ 0.08529891, 0.05068012, 0.04445121, ..., -0.00259226,\n",
+ " 0.00286377, -0.02593034],\n",
+ " ...,\n",
+ " [ 0.04170844, 0.05068012, -0.01590626, ..., -0.01107952,\n",
+ " -0.04687948, 0.01549073],\n",
+ " [-0.04547248, -0.04464164, 0.03906215, ..., 0.02655962,\n",
+ " 0.04452837, -0.02593034],\n",
+ " [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338,\n",
+ " -0.00421986, 0.00306441]])"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "diabetesdataset.data\n"
]
},
{
@@ -130,12 +257,64 @@
},
{
"cell_type": "code",
- "execution_count": 179,
- "metadata": {},
- "outputs": [],
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([151., 75., 141., 206., 135., 97., 138., 63., 110., 310., 101.,\n",
+ " 69., 179., 185., 118., 171., 166., 144., 97., 168., 68., 49.,\n",
+ " 68., 245., 184., 202., 137., 85., 131., 283., 129., 59., 341.,\n",
+ " 87., 65., 102., 265., 276., 252., 90., 100., 55., 61., 92.,\n",
+ " 259., 53., 190., 142., 75., 142., 155., 225., 59., 104., 182.,\n",
+ " 128., 52., 37., 170., 170., 61., 144., 52., 128., 71., 163.,\n",
+ " 150., 97., 160., 178., 48., 270., 202., 111., 85., 42., 170.,\n",
+ " 200., 252., 113., 143., 51., 52., 210., 65., 141., 55., 134.,\n",
+ " 42., 111., 98., 164., 48., 96., 90., 162., 150., 279., 92.,\n",
+ " 83., 128., 102., 302., 198., 95., 53., 134., 144., 232., 81.,\n",
+ " 104., 59., 246., 297., 258., 229., 275., 281., 179., 200., 200.,\n",
+ " 173., 180., 84., 121., 161., 99., 109., 115., 268., 274., 158.,\n",
+ " 107., 83., 103., 272., 85., 280., 336., 281., 118., 317., 235.,\n",
+ " 60., 174., 259., 178., 128., 96., 126., 288., 88., 292., 71.,\n",
+ " 197., 186., 25., 84., 96., 195., 53., 217., 172., 131., 214.,\n",
+ " 59., 70., 220., 268., 152., 47., 74., 295., 101., 151., 127.,\n",
+ " 237., 225., 81., 151., 107., 64., 138., 185., 265., 101., 137.,\n",
+ " 143., 141., 79., 292., 178., 91., 116., 86., 122., 72., 129.,\n",
+ " 142., 90., 158., 39., 196., 222., 277., 99., 196., 202., 155.,\n",
+ " 77., 191., 70., 73., 49., 65., 263., 248., 296., 214., 185.,\n",
+ " 78., 93., 252., 150., 77., 208., 77., 108., 160., 53., 220.,\n",
+ " 154., 259., 90., 246., 124., 67., 72., 257., 262., 275., 177.,\n",
+ " 71., 47., 187., 125., 78., 51., 258., 215., 303., 243., 91.,\n",
+ " 150., 310., 153., 346., 63., 89., 50., 39., 103., 308., 116.,\n",
+ " 145., 74., 45., 115., 264., 87., 202., 127., 182., 241., 66.,\n",
+ " 94., 283., 64., 102., 200., 265., 94., 230., 181., 156., 233.,\n",
+ " 60., 219., 80., 68., 332., 248., 84., 200., 55., 85., 89.,\n",
+ " 31., 129., 83., 275., 65., 198., 236., 253., 124., 44., 172.,\n",
+ " 114., 142., 109., 180., 144., 163., 147., 97., 220., 190., 109.,\n",
+ " 191., 122., 230., 242., 248., 249., 192., 131., 237., 78., 135.,\n",
+ " 244., 199., 270., 164., 72., 96., 306., 91., 214., 95., 216.,\n",
+ " 263., 178., 113., 200., 139., 139., 88., 148., 88., 243., 71.,\n",
+ " 77., 109., 272., 60., 54., 221., 90., 311., 281., 182., 321.,\n",
+ " 58., 262., 206., 233., 242., 123., 167., 63., 197., 71., 168.,\n",
+ " 140., 217., 121., 235., 245., 40., 52., 104., 132., 88., 69.,\n",
+ " 219., 72., 201., 110., 51., 277., 63., 118., 69., 273., 258.,\n",
+ " 43., 198., 242., 232., 175., 93., 168., 275., 293., 281., 72.,\n",
+ " 140., 189., 181., 209., 136., 261., 113., 131., 174., 257., 55.,\n",
+ " 84., 42., 146., 212., 233., 91., 111., 152., 120., 67., 310.,\n",
+ " 94., 183., 66., 173., 72., 49., 64., 48., 178., 104., 132.,\n",
+ " 220., 57.])"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "diabetesdataset.target"
]
},
{
@@ -147,12 +326,22 @@
},
{
"cell_type": "code",
- "execution_count": 180,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "from sklearn.linear_model import LinearRegression"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "linreg=LinearRegression()"
]
},
{
@@ -164,7 +353,7 @@
},
{
"cell_type": "code",
- "execution_count": 181,
+ "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@@ -192,7 +381,7 @@
},
{
"cell_type": "code",
- "execution_count": 182,
+ "execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@@ -218,12 +407,12 @@
},
{
"cell_type": "code",
- "execution_count": 183,
+ "execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
- "\n",
+ "import pandas as pd\n",
"auto = pd.read_csv('../auto-mpg.csv')"
]
},
@@ -236,12 +425,124 @@
},
{
"cell_type": "code",
- "execution_count": 184,
- "metadata": {},
- "outputs": [],
+ "execution_count": 36,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " mpg | \n",
+ " cylinders | \n",
+ " displacement | \n",
+ " horse_power | \n",
+ " weight | \n",
+ " acceleration | \n",
+ " model_year | \n",
+ " car_name | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 18.0 | \n",
+ " 8 | \n",
+ " 307.0 | \n",
+ " 130.0 | \n",
+ " 3504 | \n",
+ " 12.0 | \n",
+ " 70 | \n",
+ " \\t\"chevrolet chevelle malibu\" | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 15.0 | \n",
+ " 8 | \n",
+ " 350.0 | \n",
+ " 165.0 | \n",
+ " 3693 | \n",
+ " 11.5 | \n",
+ " 70 | \n",
+ " \\t\"buick skylark 320\" | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 18.0 | \n",
+ " 8 | \n",
+ " 318.0 | \n",
+ " 150.0 | \n",
+ " 3436 | \n",
+ " 11.0 | \n",
+ " 70 | \n",
+ " \\t\"plymouth satellite\" | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 16.0 | \n",
+ " 8 | \n",
+ " 304.0 | \n",
+ " 150.0 | \n",
+ " 3433 | \n",
+ " 12.0 | \n",
+ " 70 | \n",
+ " \\t\"amc rebel sst\" | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 17.0 | \n",
+ " 8 | \n",
+ " 302.0 | \n",
+ " 140.0 | \n",
+ " 3449 | \n",
+ " 10.5 | \n",
+ " 70 | \n",
+ " \\t\"ford torino\" | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " mpg cylinders displacement horse_power weight acceleration \\\n",
+ "0 18.0 8 307.0 130.0 3504 12.0 \n",
+ "1 15.0 8 350.0 165.0 3693 11.5 \n",
+ "2 18.0 8 318.0 150.0 3436 11.0 \n",
+ "3 16.0 8 304.0 150.0 3433 12.0 \n",
+ "4 17.0 8 302.0 140.0 3449 10.5 \n",
+ "\n",
+ " model_year car_name \n",
+ "0 70 \\t\"chevrolet chevelle malibu\" \n",
+ "1 70 \\t\"buick skylark 320\" \n",
+ "2 70 \\t\"plymouth satellite\" \n",
+ "3 70 \\t\"amc rebel sst\" \n",
+ "4 70 \\t\"ford torino\" "
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "auto.head()\n"
]
},
{
@@ -253,12 +554,31 @@
},
{
"cell_type": "code",
- "execution_count": 185,
- "metadata": {},
- "outputs": [],
+ "execution_count": 37,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "mpg float64\n",
+ "cylinders int64\n",
+ "displacement float64\n",
+ "horse_power float64\n",
+ "weight int64\n",
+ "acceleration float64\n",
+ "model_year int64\n",
+ "car_name object\n",
+ "dtype: object"
+ ]
+ },
+ "execution_count": 37,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "auto.dtypes"
]
},
{
@@ -270,12 +590,25 @@
},
{
"cell_type": "code",
- "execution_count": 186,
- "metadata": {},
- "outputs": [],
+ "execution_count": 38,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "70"
+ ]
+ },
+ "execution_count": 38,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "auto.model_year.max()\n",
+ "auto.model_year.min()"
]
},
{
@@ -287,12 +620,35 @@
},
{
"cell_type": "code",
- "execution_count": 187,
+ "execution_count": 39,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "horse_power 6\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "nan_cols=auto.isna().sum()\n",
+ "\n",
+ "nan_cols[nan_cols>0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
- "# Your code here:\n",
- "\n"
+ "auto.dropna(inplace=True)"
]
},
{
@@ -304,12 +660,28 @@
},
{
"cell_type": "code",
- "execution_count": 188,
- "metadata": {},
- "outputs": [],
+ "execution_count": 41,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "4 199\n",
+ "8 103\n",
+ "6 83\n",
+ "3 4\n",
+ "5 3\n",
+ "Name: cylinders, dtype: int64"
+ ]
+ },
+ "execution_count": 41,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "auto.cylinders.value_counts()\n"
]
},
{
@@ -323,30 +695,74 @@
},
{
"cell_type": "code",
- "execution_count": 189,
+ "execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
- "# Import the necessary function\n",
- "\n"
+ "auto.drop(columns= 'car_name', inplace=True)"
]
},
{
"cell_type": "code",
- "execution_count": 190,
+ "execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
- "# Your code here:\n",
- "\n"
+ "auto=auto.dropna(inplace=True)"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 44,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "TypeError",
+ "evalue": "'NoneType' object is not subscriptable",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mauto\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'mpg'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mauto\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mauto\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;34m'mpg'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mTypeError\u001b[0m: 'NoneType' object is not subscriptable"
+ ]
+ }
+ ],
+ "source": [
+ "y=auto['mpg']\n",
+ "x=auto[[i for i in list(auto.columns) if i != 'mpg']]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
"metadata": {},
"outputs": [],
- "source": []
+ "source": [
+ "from sklearn.model_selection import train_test_split\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'x' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx_test\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mtrain_test_split\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_size\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0;36m0.2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_test\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mtrain_test_split\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_size\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0;36m0.2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mNameError\u001b[0m: name 'x' is not defined"
+ ]
+ }
+ ],
+ "source": [
+ "x_train, x_test= train_test_split(x, test_size= 0.2)\n",
+ "y_train, y_test= train_test_split(y, test_size= 0.2)"
+ ]
},
{
"cell_type": "markdown",
@@ -357,14 +773,23 @@
},
{
"cell_type": "code",
- "execution_count": 191,
+ "execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
+ "from sklearn.linear_model import LinearRegression as LinReg\n",
+ "linreg=LinReg()\n",
"\n"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
{
"cell_type": "markdown",
"metadata": {},
@@ -374,12 +799,24 @@
},
{
"cell_type": "code",
- "execution_count": 192,
- "metadata": {},
- "outputs": [],
+ "execution_count": 51,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'x_train' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Your code here:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mlinreg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m: name 'x_train' is not defined"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "linreg.fit(x_train, y_train)\n"
]
},
{
@@ -395,22 +832,21 @@
},
{
"cell_type": "code",
- "execution_count": 193,
+ "execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
"# Import the necessary function:\n",
- "\n"
+ "from sklearn.metrics import r2_score"
]
},
{
"cell_type": "code",
- "execution_count": 194,
+ "execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
- "# Your code here:\n",
- "\n"
+ "# Your code here"
]
},
{
@@ -424,11 +860,12 @@
},
{
"cell_type": "code",
- "execution_count": 195,
+ "execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n",
+ "\n",
"\n"
]
},
@@ -445,7 +882,7 @@
},
{
"cell_type": "code",
- "execution_count": 196,
+ "execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
@@ -462,7 +899,7 @@
},
{
"cell_type": "code",
- "execution_count": 197,
+ "execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
@@ -479,7 +916,7 @@
},
{
"cell_type": "code",
- "execution_count": 198,
+ "execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
@@ -496,7 +933,7 @@
},
{
"cell_type": "code",
- "execution_count": 199,
+ "execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
@@ -531,7 +968,7 @@
},
{
"cell_type": "code",
- "execution_count": 200,
+ "execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
@@ -548,7 +985,7 @@
},
{
"cell_type": "code",
- "execution_count": 201,
+ "execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
@@ -567,7 +1004,7 @@
},
{
"cell_type": "code",
- "execution_count": 202,
+ "execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
@@ -584,7 +1021,7 @@
},
{
"cell_type": "code",
- "execution_count": 203,
+ "execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
@@ -616,7 +1053,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.6"
+ "version": "3.8.5"
}
},
"nbformat": 4,