Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Module 5Coding Assignment: Linear Regression with Python

1 answer below »
Module 5Coding Assignment: Linear Regression with Python
Answered Same Day Jun 25, 2021

Solution

Harsimran answered on Jun 26 2021
130 Votes
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"deletable": false,
"editable": false,
"id": "viK_dHiXBEo2",
"nbgrader": {
"grade": false,
"locked": true,
"solution": false
}
},
"source": [
"# Module 5: Linear Regression - Interactions and Transformations\n",
"\n",
"**_Author:Favio Vázquez and Jessica Cervi_**\n",
"\n",
" In this assignment, we will perform some feature transformation on a database describing airplane accidents and next, we will study a complete example of linear regression.\n",
" \n",
" \n",
" a>\n",
"### Index:\n",
"\n",
"\n",
"- [Question 1](#q01)\n",
"- [Question 2](#q02)\n",
"- [Question 3](#q03)\n",
"- [Question 4](#q04)\n",
"- [Question 5](#q05)\n",
"- [Question 6](#q06)\n",
"- [Question 7](#q07)\n",
"- [Question 8](#q08)\n",
"- [Question 9](#q09)\n",
"- [Question 10](#q10)\n",
"- [Question 11](#q11)\n",
"- [Question 12](#q12)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"deletable": false,
"editable": false,
"id": "qY13QYshBEo3",
"nbgrader": {
"grade": false,
"locked": true,
"solution": false
}
},
"source": [
"## Import the necessary li
aries"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true,
"deletable": false,
"editable": false,
"nbgrader": {
"grade": false,
"locked": true,
"solution": false
}
},
"outputs": [],
"source": [
"## DON'T CHANGE THIS CODE\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"grade": false,
"locked": true,
"solution": false
}
},
"source": [
"
a>\n",
"[Return to top](#questions)\n",
"\n",
"## Question 1\n",
"\n",
"Read the CSV file named \"airplane_crash.csv\" in the `data` folder and assign it to a dataframe called `accident`. Next, drop the column `Summary` using the `pandas` command `drop` ."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['Date', 'Time', 'Location', 'Operator', 'Flight #', 'Route', 'Type',\n",
" 'Registration', 'cn/In', 'Aboard', 'Fatalities', 'Ground', 'Summary'],\n",
" dtype='object')\n",
"Index(['Date', 'Time', 'Location', 'Operator', 'Flight #', 'Route', 'Type',\n",
" 'Registration', 'cn/In', 'Aboard', 'Fatalities', 'Ground'],\n",
" dtype='object')\n"
]
},
{
"data": {
"text/plain": [
"Index(['Date', 'Time', 'Location', 'Operator', 'Flight #', 'Route', 'Type',\n",
" 'Registration', 'cn/In', 'Aboard', 'Fatalities', 'Ground'],\n",
" dtype='object')"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"### GRADED\n",
"\n",
"### YOUR SOLUTION HERE\n",
"accident = pd.read_csv(\"data/airplane_crash.csv\")\n",
"#print(accident.columns)\n",
"\n",
"###\n",
"### YOUR CODE HERE\n",
"accident = accident.drop('Summary', 1)\n",
"\n",
"###\n",
"\n",
"### Answer check\n",
"accident.columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": false,
"editable": false,
"nbgrader": {
"grade": true,
"grade_id": "Question 01",
"locked": true,
"points": "10",
"solution": false
}
},
"outputs": [],
"source": [
"###\n",
"### AUTOGRADER TEST - DO NOT REMOVE\n",
"###\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"grade": false,
"locked": true,
"solution": false
}
},
"source": [
"Now we extract the info and visuaize the first 10 rows of our dataframe"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"grade": false,
"locked": true,
"solution": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"RangeIndex: 5268 entries, 0 to 5267\n",
"Data columns (total 12 columns):\n",
"Date 5268 non-null object\n",
"Time 3049 non-null object\n",
"Location 5248 non-null object\n",
"Operator 5250 non-null object\n",
"Flight # 1069 non-null object\n",
"Route 3562 non-null object\n",
"Type 5241 non-null object\n",
"Registration 4933 non-null object\n",
"cn/In 4040 non-null object\n",
"Aboard 5161 non-null float64\n",
"Fatalities 5256 non-null float64\n",
"Ground 5246 non-null float64\n",
"dtypes: float64(3), object(9)\n",
"memory usage: 494.0+ KB\n"
]
}
],
"source": [
"## DON'T CHANGE THIS CODE\n",
"accident.info()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"grade": false,
"locked": true,
"solution": false
}
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"