Created
February 2, 2020 10:16
-
-
Save depindersharma/c233c9ba09fa38fbcec08f5e64d5990b to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"<a href=\"https://www.bigdatauniversity.com\"><img src=\"https://ibm.box.com/shared/static/cw2c7r3o20w9zn8gkecaeyjhgw3xdgbj.png\" width=\"400\" align=\"center\"></a>\n", | |
"\n", | |
"<h1><center>Simple Linear Regression</center></h1>\n", | |
"\n", | |
"\n", | |
"<h4>About this Notebook</h4>\n", | |
"In this notebook, we learn how to use scikit-learn to implement simple linear regression. We download a dataset that is related to fuel consumption and Carbon dioxide emission of cars. Then, we split our data into training and test sets, create a model using training set, evaluate your model using test set, and finally use model to predict unknown value.\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<h1>Table of contents</h1>\n", | |
"\n", | |
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n", | |
" <ol>\n", | |
" <li><a href=\"#understanding_data\">Understanding the Data</a></li>\n", | |
" <li><a href=\"#reading_data\">Reading the data in</a></li>\n", | |
" <li><a href=\"#data_exploration\">Data Exploration</a></li>\n", | |
" <li><a href=\"#simple_regression\">Simple Regression Model</a></li>\n", | |
" </ol>\n", | |
"</div>\n", | |
"<br>\n", | |
"<hr>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"### Importing Needed packages" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"import matplotlib.pyplot as plt\n", | |
"import pandas as pd\n", | |
"import pylab as pl\n", | |
"import numpy as np\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"### Downloading Data\n", | |
"To download the data, we will use !wget to download it from IBM Object Storage." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"--2020-01-06 13:00:27-- https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/FuelConsumptionCo2.csv\n", | |
"Resolving s3-api.us-geo.objectstorage.softlayer.net (s3-api.us-geo.objectstorage.softlayer.net)... 67.228.254.196\n", | |
"Connecting to s3-api.us-geo.objectstorage.softlayer.net (s3-api.us-geo.objectstorage.softlayer.net)|67.228.254.196|:443... connected.\n", | |
"HTTP request sent, awaiting response... 200 OK\n", | |
"Length: 72629 (71K) [text/csv]\n", | |
"Saving to: ‘FuelConsumption.csv’\n", | |
"\n", | |
"FuelConsumption.csv 100%[===================>] 70.93K --.-KB/s in 0.04s \n", | |
"\n", | |
"2020-01-06 13:00:27 (1.62 MB/s) - ‘FuelConsumption.csv’ saved [72629/72629]\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"!wget -O FuelConsumption.csv https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/FuelConsumptionCo2.csv" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"__Did you know?__ When it comes to Machine Learning, you will likely be working with large datasets. As a business, where can you host your data? IBM is offering a unique opportunity for businesses, with 10 Tb of IBM Cloud Object Storage: [Sign up now for free](http://cocl.us/ML0101EN-IBM-Offer-CC)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"\n", | |
"<h2 id=\"understanding_data\">Understanding the Data</h2>\n", | |
"\n", | |
"### `FuelConsumption.csv`:\n", | |
"We have downloaded a fuel consumption dataset, **`FuelConsumption.csv`**, which contains model-specific fuel consumption ratings and estimated carbon dioxide emissions for new light-duty vehicles for retail sale in Canada. [Dataset source](http://open.canada.ca/data/en/dataset/98f1a129-f628-4ce4-b24d-6f16bf24dd64)\n", | |
"\n", | |
"- **MODELYEAR** e.g. 2014\n", | |
"- **MAKE** e.g. Acura\n", | |
"- **MODEL** e.g. ILX\n", | |
"- **VEHICLE CLASS** e.g. SUV\n", | |
"- **ENGINE SIZE** e.g. 4.7\n", | |
"- **CYLINDERS** e.g 6\n", | |
"- **TRANSMISSION** e.g. A6\n", | |
"- **FUEL CONSUMPTION in CITY(L/100 km)** e.g. 9.9\n", | |
"- **FUEL CONSUMPTION in HWY (L/100 km)** e.g. 8.9\n", | |
"- **FUEL CONSUMPTION COMB (L/100 km)** e.g. 9.2\n", | |
"- **CO2 EMISSIONS (g/km)** e.g. 182 --> low --> 0\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"<h2 id=\"reading_data\">Reading the data in</h2>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>MODELYEAR</th>\n", | |
" <th>MAKE</th>\n", | |
" <th>MODEL</th>\n", | |
" <th>VEHICLECLASS</th>\n", | |
" <th>ENGINESIZE</th>\n", | |
" <th>CYLINDERS</th>\n", | |
" <th>TRANSMISSION</th>\n", | |
" <th>FUELTYPE</th>\n", | |
" <th>FUELCONSUMPTION_CITY</th>\n", | |
" <th>FUELCONSUMPTION_HWY</th>\n", | |
" <th>FUELCONSUMPTION_COMB</th>\n", | |
" <th>FUELCONSUMPTION_COMB_MPG</th>\n", | |
" <th>CO2EMISSIONS</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>2014</td>\n", | |
" <td>ACURA</td>\n", | |
" <td>ILX</td>\n", | |
" <td>COMPACT</td>\n", | |
" <td>2.0</td>\n", | |
" <td>4</td>\n", | |
" <td>AS5</td>\n", | |
" <td>Z</td>\n", | |
" <td>9.9</td>\n", | |
" <td>6.7</td>\n", | |
" <td>8.5</td>\n", | |
" <td>33</td>\n", | |
" <td>196</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2014</td>\n", | |
" <td>ACURA</td>\n", | |
" <td>ILX</td>\n", | |
" <td>COMPACT</td>\n", | |
" <td>2.4</td>\n", | |
" <td>4</td>\n", | |
" <td>M6</td>\n", | |
" <td>Z</td>\n", | |
" <td>11.2</td>\n", | |
" <td>7.7</td>\n", | |
" <td>9.6</td>\n", | |
" <td>29</td>\n", | |
" <td>221</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>2014</td>\n", | |
" <td>ACURA</td>\n", | |
" <td>ILX HYBRID</td>\n", | |
" <td>COMPACT</td>\n", | |
" <td>1.5</td>\n", | |
" <td>4</td>\n", | |
" <td>AV7</td>\n", | |
" <td>Z</td>\n", | |
" <td>6.0</td>\n", | |
" <td>5.8</td>\n", | |
" <td>5.9</td>\n", | |
" <td>48</td>\n", | |
" <td>136</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>2014</td>\n", | |
" <td>ACURA</td>\n", | |
" <td>MDX 4WD</td>\n", | |
" <td>SUV - SMALL</td>\n", | |
" <td>3.5</td>\n", | |
" <td>6</td>\n", | |
" <td>AS6</td>\n", | |
" <td>Z</td>\n", | |
" <td>12.7</td>\n", | |
" <td>9.1</td>\n", | |
" <td>11.1</td>\n", | |
" <td>25</td>\n", | |
" <td>255</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>2014</td>\n", | |
" <td>ACURA</td>\n", | |
" <td>RDX AWD</td>\n", | |
" <td>SUV - SMALL</td>\n", | |
" <td>3.5</td>\n", | |
" <td>6</td>\n", | |
" <td>AS6</td>\n", | |
" <td>Z</td>\n", | |
" <td>12.1</td>\n", | |
" <td>8.7</td>\n", | |
" <td>10.6</td>\n", | |
" <td>27</td>\n", | |
" <td>244</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" MODELYEAR MAKE MODEL VEHICLECLASS ENGINESIZE CYLINDERS \\\n", | |
"0 2014 ACURA ILX COMPACT 2.0 4 \n", | |
"1 2014 ACURA ILX COMPACT 2.4 4 \n", | |
"2 2014 ACURA ILX HYBRID COMPACT 1.5 4 \n", | |
"3 2014 ACURA MDX 4WD SUV - SMALL 3.5 6 \n", | |
"4 2014 ACURA RDX AWD SUV - SMALL 3.5 6 \n", | |
"\n", | |
" TRANSMISSION FUELTYPE FUELCONSUMPTION_CITY FUELCONSUMPTION_HWY \\\n", | |
"0 AS5 Z 9.9 6.7 \n", | |
"1 M6 Z 11.2 7.7 \n", | |
"2 AV7 Z 6.0 5.8 \n", | |
"3 AS6 Z 12.7 9.1 \n", | |
"4 AS6 Z 12.1 8.7 \n", | |
"\n", | |
" FUELCONSUMPTION_COMB FUELCONSUMPTION_COMB_MPG CO2EMISSIONS \n", | |
"0 8.5 33 196 \n", | |
"1 9.6 29 221 \n", | |
"2 5.9 48 136 \n", | |
"3 11.1 25 255 \n", | |
"4 10.6 27 244 " | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df = pd.read_csv(\"FuelConsumption.csv\")\n", | |
"\n", | |
"# take a look at the dataset\n", | |
"df.head()\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"<h2 id=\"data_exploration\">Data Exploration</h2>\n", | |
"Lets first have a descriptive exploration on our data." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>MODELYEAR</th>\n", | |
" <th>ENGINESIZE</th>\n", | |
" <th>CYLINDERS</th>\n", | |
" <th>FUELCONSUMPTION_CITY</th>\n", | |
" <th>FUELCONSUMPTION_HWY</th>\n", | |
" <th>FUELCONSUMPTION_COMB</th>\n", | |
" <th>FUELCONSUMPTION_COMB_MPG</th>\n", | |
" <th>CO2EMISSIONS</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>count</th>\n", | |
" <td>1067.0</td>\n", | |
" <td>1067.000000</td>\n", | |
" <td>1067.000000</td>\n", | |
" <td>1067.000000</td>\n", | |
" <td>1067.000000</td>\n", | |
" <td>1067.000000</td>\n", | |
" <td>1067.000000</td>\n", | |
" <td>1067.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>mean</th>\n", | |
" <td>2014.0</td>\n", | |
" <td>3.346298</td>\n", | |
" <td>5.794752</td>\n", | |
" <td>13.296532</td>\n", | |
" <td>9.474602</td>\n", | |
" <td>11.580881</td>\n", | |
" <td>26.441425</td>\n", | |
" <td>256.228679</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>std</th>\n", | |
" <td>0.0</td>\n", | |
" <td>1.415895</td>\n", | |
" <td>1.797447</td>\n", | |
" <td>4.101253</td>\n", | |
" <td>2.794510</td>\n", | |
" <td>3.485595</td>\n", | |
" <td>7.468702</td>\n", | |
" <td>63.372304</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>min</th>\n", | |
" <td>2014.0</td>\n", | |
" <td>1.000000</td>\n", | |
" <td>3.000000</td>\n", | |
" <td>4.600000</td>\n", | |
" <td>4.900000</td>\n", | |
" <td>4.700000</td>\n", | |
" <td>11.000000</td>\n", | |
" <td>108.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>25%</th>\n", | |
" <td>2014.0</td>\n", | |
" <td>2.000000</td>\n", | |
" <td>4.000000</td>\n", | |
" <td>10.250000</td>\n", | |
" <td>7.500000</td>\n", | |
" <td>9.000000</td>\n", | |
" <td>21.000000</td>\n", | |
" <td>207.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>50%</th>\n", | |
" <td>2014.0</td>\n", | |
" <td>3.400000</td>\n", | |
" <td>6.000000</td>\n", | |
" <td>12.600000</td>\n", | |
" <td>8.800000</td>\n", | |
" <td>10.900000</td>\n", | |
" <td>26.000000</td>\n", | |
" <td>251.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>75%</th>\n", | |
" <td>2014.0</td>\n", | |
" <td>4.300000</td>\n", | |
" <td>8.000000</td>\n", | |
" <td>15.550000</td>\n", | |
" <td>10.850000</td>\n", | |
" <td>13.350000</td>\n", | |
" <td>31.000000</td>\n", | |
" <td>294.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>max</th>\n", | |
" <td>2014.0</td>\n", | |
" <td>8.400000</td>\n", | |
" <td>12.000000</td>\n", | |
" <td>30.200000</td>\n", | |
" <td>20.500000</td>\n", | |
" <td>25.800000</td>\n", | |
" <td>60.000000</td>\n", | |
" <td>488.000000</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" MODELYEAR ENGINESIZE CYLINDERS FUELCONSUMPTION_CITY \\\n", | |
"count 1067.0 1067.000000 1067.000000 1067.000000 \n", | |
"mean 2014.0 3.346298 5.794752 13.296532 \n", | |
"std 0.0 1.415895 1.797447 4.101253 \n", | |
"min 2014.0 1.000000 3.000000 4.600000 \n", | |
"25% 2014.0 2.000000 4.000000 10.250000 \n", | |
"50% 2014.0 3.400000 6.000000 12.600000 \n", | |
"75% 2014.0 4.300000 8.000000 15.550000 \n", | |
"max 2014.0 8.400000 12.000000 30.200000 \n", | |
"\n", | |
" FUELCONSUMPTION_HWY FUELCONSUMPTION_COMB FUELCONSUMPTION_COMB_MPG \\\n", | |
"count 1067.000000 1067.000000 1067.000000 \n", | |
"mean 9.474602 11.580881 26.441425 \n", | |
"std 2.794510 3.485595 7.468702 \n", | |
"min 4.900000 4.700000 11.000000 \n", | |
"25% 7.500000 9.000000 21.000000 \n", | |
"50% 8.800000 10.900000 26.000000 \n", | |
"75% 10.850000 13.350000 31.000000 \n", | |
"max 20.500000 25.800000 60.000000 \n", | |
"\n", | |
" CO2EMISSIONS \n", | |
"count 1067.000000 \n", | |
"mean 256.228679 \n", | |
"std 63.372304 \n", | |
"min 108.000000 \n", | |
"25% 207.000000 \n", | |
"50% 251.000000 \n", | |
"75% 294.000000 \n", | |
"max 488.000000 " | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# summarize the data\n", | |
"df.describe()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Lets select some features to explore more." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>ENGINESIZE</th>\n", | |
" <th>CYLINDERS</th>\n", | |
" <th>FUELCONSUMPTION_COMB</th>\n", | |
" <th>CO2EMISSIONS</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>2.0</td>\n", | |
" <td>4</td>\n", | |
" <td>8.5</td>\n", | |
" <td>196</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2.4</td>\n", | |
" <td>4</td>\n", | |
" <td>9.6</td>\n", | |
" <td>221</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>1.5</td>\n", | |
" <td>4</td>\n", | |
" <td>5.9</td>\n", | |
" <td>136</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>3.5</td>\n", | |
" <td>6</td>\n", | |
" <td>11.1</td>\n", | |
" <td>255</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>3.5</td>\n", | |
" <td>6</td>\n", | |
" <td>10.6</td>\n", | |
" <td>244</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>3.5</td>\n", | |
" <td>6</td>\n", | |
" <td>10.0</td>\n", | |
" <td>230</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>3.5</td>\n", | |
" <td>6</td>\n", | |
" <td>10.1</td>\n", | |
" <td>232</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>3.7</td>\n", | |
" <td>6</td>\n", | |
" <td>11.1</td>\n", | |
" <td>255</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>3.7</td>\n", | |
" <td>6</td>\n", | |
" <td>11.6</td>\n", | |
" <td>267</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" ENGINESIZE CYLINDERS FUELCONSUMPTION_COMB CO2EMISSIONS\n", | |
"0 2.0 4 8.5 196\n", | |
"1 2.4 4 9.6 221\n", | |
"2 1.5 4 5.9 136\n", | |
"3 3.5 6 11.1 255\n", | |
"4 3.5 6 10.6 244\n", | |
"5 3.5 6 10.0 230\n", | |
"6 3.5 6 10.1 232\n", | |
"7 3.7 6 11.1 255\n", | |
"8 3.7 6 11.6 267" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"cdf = df[['ENGINESIZE','CYLINDERS','FUELCONSUMPTION_COMB','CO2EMISSIONS']]\n", | |
"cdf.head(9)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"we can plot each of these features:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAEICAYAAAC3Y/QeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dfZxdVX3v8c+X8PygIY6EAIFBTXkJxlYbEYvVUaE8arAIDSIQC+XWgoJGJXgRpFdatBd8hNsbCyVIBKM8BdTyVKYUroCEohACEiRCJCQCQhhEauB3/1hrcOdkn5kzJ3PmnDP7+369zmvOWftp7T17/846a629tiICMzOrlo3anQEzMxt7Dv5mZhXk4G9mVkEO/mZmFeTgb2ZWQQ7+ZmYV5OBvZlZBlQ7+kj4s6S5JA5JWSvqRpHfmabtLWiTpWUnPSbpZ0p8Vlv0jSVdL+rWkpyVdJ2m3wvQvSPp9Xvfg65nC9JC0StLGhbSNJa2WFIW0fknHFT5/TtIjeX0rJH23MG0PSddL+o2kZyQtlnRgntYnaUXN/h8s6U5Jz0t6StICSTsVps/O+fxMzXIrJPXl9xMlXSjpiXycfi7plCb/JdZh6lwjn8/nbk9hvs0kLZX0PyT15vNm45L1fUHSJYXPIeleSRsV0r4o6aL8fnBdg9fQKknXStq3Zr3LJb1Qc719M0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HF2/Al9QGfjoiD25TNdUhaDsyIiNIbTyQdCHwcOJB0Y9HXImK9G4zaIQ978Cvg7RHxy0J6Hx10jKtM0ruAAeDiiHhTTvsy8HREnJ3HKdo2Ik5pZz5boV48AGYzzve/ciX/iFgZEXfn988BS0l3Z3azmaQLNyLidmBiPqk7wfuAh4uB3zpLRNwCPF2TPBOYn9/PJwXEcWeIeDDu979ywb9IUi/wFuCOksnvkPRTST+StMeYZmx9AVwvaXEeHqBW2dACnfKFNgu4tM60TjrGtq7JEbESUoAEtmtzflquJh6M+/2v7Hj+krYGLgdOjog1NZPvBnaJiIFcpXIVMG2s81iwd0Q8Lmk74AZJD+TS2qCGhhYYa/lmpw8Ap5ZM7rRjbBVWGw+ksktqfKlkyV/SJqR/9IKIuKJ2ekSsiYiB/P6HwCaSesY4m8X8PJ7/rgauJI0gWdSpQwscANwdEatqJ3TaMbb1rBqsOsx/V7c5Py1TJx6M+/2vXPBX+kq/AFgaEefWmWf7PB+S9iQdp6fGLpfr5GWr3BCFpK2AvwDuq5ltEXB07vWzF/Ds4E/WNjuCOlU+nXSMrdQi4Jj8/hjg6jbmpWWGiAfjfv+r2NvnncB/AvcCL+fkzwE7A0TEP+fb9D8GrAVeAD4VEf+vDdlF0utIpX1I1XTfiYizJP1tIb8CvgnsD/wW+GhErNcldCxJ2pLUDvG6iHg2pxXz3DHHuOokXQr0kYYyXgWcQaqGW0i6Lh4FDouI2kbhrjdEPLiDcb7/lQv+ZmZWwWofMzNz8DczqyQHfzOzCnLwNzOrIAd/M7MKcvA3M6sgB38zswr6/2Vb6j24kZMKAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 4 Axes>" | |
] | |
}, | |
"metadata": { | |
"needs_background": "light" | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"viz = cdf[['CYLINDERS','ENGINESIZE','CO2EMISSIONS','FUELCONSUMPTION_COMB']]\n", | |
"viz.hist()\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Now, lets plot each of these features vs the Emission, to see how linear is their relation:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEICAYAAACwDehOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de7SddX3n8fcnJwEJlxJKoLmRUAztnGNrtGeYaXE51hwKg1RkpmpooNBxJpeNI70qMZ2lY1c6TMcL9kIgVkZKtmJW1YFStSURlnbqkgaMQIKUdEhCAkOCQjXEoST5zh/Ps0+enLMvzz7Zz75+Xmudtff+7efZ+3eenOzv/t2+P0UEZmZmANM6XQEzM+seDgpmZjbOQcHMzMY5KJiZ2TgHBTMzG+egYGZm46YX+eKSdgE/BI4AhyNiVNJZwOeBRcAu4F0R8WJ6/BrgPenx74uIv673+meffXYsWrSoqOqbmfWlhx9++IWImF3tuUKDQuoXI+KFzOObgC0RcbOkm9LHH5A0DCwDRoC5wGZJF0bEkVovvGjRIrZu3Vpk3c3M+o6k3bWe60T30ZXAnen9O4F3ZMrvjohXIuJpYCdwUQfqZ2Y2sIoOCgH8jaSHJa1Iy86NiOcA0ttz0vJ5wDOZc/emZWZm1iZFdx9dHBHPSjoHuF/Sd+scqyplk3JwpMFlBcB5553XmlqamRlQcEshIp5Nb/cDXyLpDnpe0hyA9HZ/evheYEHm9PnAs1Vec0NEjEbE6OzZVcdJzMxsigoLCpJOlXR65T7wS8DjwL3Adelh1wH3pPfvBZZJOlnS+cBi4KGi6mdmZpMV2VI4F/hbSd8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8vRrgT1VMplOvH53A8vSFtvPcizdc8W7JW0jaUGcBfwl1lMcFKzVst1HV6VltXKpZMuz3UefmOJ7q8Z7TSz7I+A6SWeMHxBxkORb+QqSb9+fz/TN53nNu0m6jZZR/dtzOf2wvBj4nfq/xrhav89x5RHxNPAQSStqKq/XzHs9CiwiaSV8ucrxn0+7xX6CJPj9boM6WZdxULB2+B4wcbOQs0j695u1neTDu9ZzoxPKfg7YkS2IiJdIxh5KE8qPRMSDEfEh4L3Av0+fmlj/SXWPiIdIWjFnR8Q/VKnb8jTgvSMi8o5VbAfeIGn8/2l6//UkO3Vl/QHwAer8n05bAS8rSQA50U5gYdqayHojE64fSUvoo9ToOkrfK0haCd6XpMc4KFg7/D1wcToQTDqz5mTyD+RmfRb4hezgsaTLJP0M8KfA9ZKWpOU/Dvx34A+rvM7HgZUkWXFJZwQtzjy/BNid3n8QuDY9bgi4BnigymuuIemzb4mI2Al8G/i9TPHvAY+kz2WP/S7Jh/cVDV72vwF/WmklSTpD0oqIeJlkEPzjlW6odFbSTOBrE17jDuAjEdGoG+xNQLWuKuti0ztdAet/EfG8pBuBL6ffdA8CV6cbiVQ8IKnSd/5oRPxaev92Sbek95+JiJ+XdAVwS1r+KvAocGP6PtcAn0q/8Qq4JTsonanTC+mYR2X84jTgjyWdCRwm+eZcmc76+8B6Sd9JX/OrwMYqr/mVpi9OY+9J67Uzfe9vpmXVrCMJIvWsJ/ld/17SqyTXr7K71xqSFsA/SDoKfBe4KiakUo6IvcAna7z+u5WkhZ4G7AWub1Af6zJOnW1mZuPcfWRmZuPcfWTWhyT9KclMp6xPpmsPzGpy95GZmY1z95GZmY1zUDAzs3EOCmZmNs5BwczMxjkomJnZuP8PgjC7itdQiLQAAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": { | |
"needs_background": "light" | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"plt.scatter(cdf.FUELCONSUMPTION_COMB, cdf.CO2EMISSIONS, color='blue')\n", | |
"plt.xlabel(\"FUELCONSUMPTION_COMB\")\n", | |
"plt.ylabel(\"Emission\")\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"button": false, | |
"collapsed": true, | |
"deletable": true, | |
"jupyter": { | |
"outputs_hidden": true | |
}, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
}, | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"plt.scatter(cdf.ENGINESIZE, cdf.CO2EMISSIONS, color='blue')\n", | |
"plt.xlabel(\"Engine size\")\n", | |
"plt.ylabel(\"Emission\")\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Practice\n", | |
"plot __CYLINDER__ vs the Emission, to see how linear is their relation:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEHCAYAAABBW1qbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAdC0lEQVR4nO3dfZBddZ3n8feHbhKJ4vDUsCEh6QwG3AQ1undSsuy4SsLCIku0arXitpqaoaZZGhd0ZlbJZqZkHzJSOzhI7W6HaYUlNfaYSfmwpBhESQfKh3XADkQkQYbMJoQmkbQPMyJhoul8949z+vbt7tude5N77rnd5/OqunXO73t+5/SXS5Jvn6ffTxGBmZkZwGl5J2BmZq3DRcHMzMpcFMzMrMxFwczMylwUzMyszEXBzMzK2rM8uKT9wCvACHAsIkqSzg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|
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": { | |
"needs_background": "light" | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"plt.scatter(cdf.CYLINDERS, cdf.CO2EMISSIONS, color='blue')\n", | |
"plt.xlabel(\"CYLINDERS\")\n", | |
"plt.ylabel(\"Emission\")\n", | |
"plt.show()\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Double-click __here__ for the solution.\n", | |
"\n", | |
"<!-- Your answer is below:\n", | |
" \n", | |
"plt.scatter(cdf.CYLINDERS, cdf.CO2EMISSIONS, color='blue')\n", | |
"plt.xlabel(\"Cylinders\")\n", | |
"plt.ylabel(\"Emission\")\n", | |
"plt.show()\n", | |
"\n", | |
"-->" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"#### Creating train and test dataset\n", | |
"Train/Test Split involves splitting the dataset into training and testing sets respectively, which are mutually exclusive. After which, you train with the training set and test with the testing set. \n", | |
"This will provide a more accurate evaluation on out-of-sample accuracy because the testing dataset is not part of the dataset that have been used to train the data. It is more realistic for real world problems.\n", | |
"\n", | |
"This means that we know the outcome of each data point in this dataset, making it great to test with! And since this data has not been used to train the model, the model has no knowledge of the outcome of these data points. So, in essence, it is truly an out-of-sample testing.\n", | |
"\n", | |
"Lets split our dataset into train and test sets, 80% of the entire data for training, and the 20% for testing. We create a mask to select random rows using __np.random.rand()__ function: " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"button": false, | |
"collapsed": true, | |
"deletable": true, | |
"jupyter": { | |
"outputs_hidden": true | |
}, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"msk = np.random.rand(len(df)) < 0.8\n", | |
"train = cdf[msk]\n", | |
"test = cdf[~msk]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"<h2 id=\"simple_regression\">Simple Regression Model</h2>\n", | |
"Linear Regression fits a linear model with coefficients $\\theta = (\\theta_1, ..., \\theta_n)$ to minimize the 'residual sum of squares' between the independent x in the dataset, and the dependent y by the linear approximation. " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"#### Train data distribution" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name '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<ipython-input-12-c6ba1ff911b5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mENGINESIZE\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCO2EMISSIONS\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'blue'\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[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mxlabel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Engine size\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mylabel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Emission\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow\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;31mNameError\u001b[0m: name 'train' is not defined" | |
] | |
} | |
], | |
"source": [ | |
"plt.scatter(train.ENGINESIZE, train.CO2EMISSIONS, color='blue')\n", | |
"plt.xlabel(\"Engine size\")\n", | |
"plt.ylabel(\"Emission\")\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"#### Modeling\n", | |
"Using sklearn package to model data." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name '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<ipython-input-13-d6fc4367c750>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mlinear_model\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mregr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlinear_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mLinearRegression\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;32m----> 3\u001b[0;31m \u001b[0mtrain_x\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masanyarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'ENGINESIZE'\u001b[0m\u001b[0;34m]\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[0m\u001b[1;32m 4\u001b[0m \u001b[0mtrain_y\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masanyarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'CO2EMISSIONS'\u001b[0m\u001b[0;34m]\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[1;32m 5\u001b[0m \u001b[0mregr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mtrain_x\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtrain_y\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 'train' is not defined" | |
] | |
} | |
], | |
"source": [ | |
"from sklearn import linear_model\n", | |
"regr = linear_model.LinearRegression()\n", | |
"train_x = np.asanyarray(train[['ENGINESIZE']])\n", | |
"train_y = np.asanyarray(train[['CO2EMISSIONS']])\n", | |
"regr.fit (train_x, train_y)\n", | |
"# The coefficients\n", | |
"print ('Coefficients: ', regr.coef_)\n", | |
"print ('Intercept: ',regr.intercept_)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"As mentioned before, __Coefficient__ and __Intercept__ in the simple linear regression, are the parameters of the fit line. \n", | |
"Given that it is a simple linear regression, with only 2 parameters, and knowing that the parameters are the intercept and slope of the line, sklearn can estimate them directly from our data. \n", | |
"Notice that all of the data must be available to traverse and calculate the parameters.\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"#### Plot outputs" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"we can plot the fit line over the data:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name '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<ipython-input-14-ea27f013dd36>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mENGINESIZE\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCO2EMISSIONS\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'blue'\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[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_x\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mregr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcoef_\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mtrain_x\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mregr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mintercept_\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'-r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mxlabel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Engine size\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mylabel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Emission\"\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 'train' is not defined" | |
] | |
} | |
], | |
"source": [ | |
"plt.scatter(train.ENGINESIZE, train.CO2EMISSIONS, color='blue')\n", | |
"plt.plot(train_x, regr.coef_[0][0]*train_x + regr.intercept_[0], '-r')\n", | |
"plt.xlabel(\"Engine size\")\n", | |
"plt.ylabel(\"Emission\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"#### Evaluation\n", | |
"we compare the actual values and predicted values to calculate the accuracy of a regression model. Evaluation metrics provide a key role in the development of a model, as it provides insight to areas that require improvement.\n", | |
"\n", | |
"There are different model evaluation metrics, lets use MSE here to calculate the accuracy of our model based on the test set: \n", | |
"<ul>\n", | |
" <li> Mean absolute error: It is the mean of the absolute value of the errors. This is the easiest of the metrics to understand since it’s just average error.</li>\n", | |
" <li> Mean Squared Error (MSE): Mean Squared Error (MSE) is the mean of the squared error. It’s more popular than Mean absolute error because the focus is geared more towards large errors. This is due to the squared term exponentially increasing larger errors in comparison to smaller ones.</li>\n", | |
" <li> Root Mean Squared Error (RMSE): This is the square root of the Mean Square Error. </li>\n", | |
" <li> R-squared is not error, but is a popular metric for accuracy of your model. It represents how close the data are to the fitted regression line. The higher the R-squared, the better the model fits your data. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).</li>\n", | |
"</ul>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"button": false, | |
"collapsed": true, | |
"deletable": true, | |
"jupyter": { | |
"outputs_hidden": true | |
}, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
}, | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from sklearn.metrics import r2_score\n", | |
"\n", | |
"test_x = np.asanyarray(test[['ENGINESIZE']])\n", | |
"test_y = np.asanyarray(test[['CO2EMISSIONS']])\n", | |
"test_y_hat = regr.predict(test_x)\n", | |
"\n", | |
"print(\"Mean absolute error: %.2f\" % np.mean(np.absolute(test_y_hat - test_y)))\n", | |
"print(\"Residual sum of squares (MSE): %.2f\" % np.mean((test_y_hat - test_y) ** 2))\n", | |
"print(\"R2-score: %.2f\" % r2_score(test_y_hat , test_y) )" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"button": false, | |
"deletable": true, | |
"new_sheet": false, | |
"run_control": { | |
"read_only": false | |
} | |
}, | |
"source": [ | |
"<h2>Want to learn more?</h2>\n", | |
"\n", | |
"IBM SPSS Modeler is a comprehensive analytics platform that has many machine learning algorithms. It has been designed to bring predictive intelligence to decisions made by individuals, by groups, by systems – by your enterprise as a whole. A free trial is available through this course, available here: <a href=\"http://cocl.us/ML0101EN-SPSSModeler\">SPSS Modeler</a>\n", | |
"\n", | |
"Also, you can use Watson Studio to run these notebooks faster with bigger datasets. Watson Studio is IBM's leading cloud solution for data scientists, built by data scientists. With Jupyter notebooks, RStudio, Apache Spark and popular libraries pre-packaged in the cloud, Watson Studio enables data scientists to collaborate on their projects without having to install anything. Join the fast-growing community of Watson Studio users today with a free account at <a href=\"https://cocl.us/ML0101EN_DSX\">Watson Studio</a>\n", | |
"\n", | |
"<h3>Thanks for completing this lesson!</h3>\n", | |
"\n", | |
"<h4>Author: <a href=\"https://ca.linkedin.com/in/saeedaghabozorgi\">Saeed Aghabozorgi</a></h4>\n", | |
"<p><a href=\"https://ca.linkedin.com/in/saeedaghabozorgi\">Saeed Aghabozorgi</a>, PhD is a Data Scientist in IBM with a track record of developing enterprise level applications that substantially increases clients’ ability to turn data into actionable knowledge. He is a researcher in data mining field and expert in developing advanced analytic methods like machine learning and statistical modelling on large datasets.</p>\n", | |
"\n", | |
"<hr>\n", | |
"\n", | |
"<p>Copyright © 2018 <a href=\"https://cocl.us/DX0108EN_CC\">Cognitive Class</a>. This notebook and its source code are released under the terms of the <a href=\"https://bigdatauniversity.com/mit-license/\">MIT License</a>.</p>" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python", | |
"language": "python", | |
"name": "conda-env-python-py" | |
}, | |
"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.6.7" | |
}, | |
"widgets": { | |
"state": {}, | |
"version": "1.1.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment