Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A HANDS-ON GUIDE TO REGRESSION WITH FAST.AI
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Regression_Using_Fastai.ipynb",
"provenance": [],
"collapsed_sections": [
"Mv5lcQQ9egIE",
"ZTmAW33KefrK"
]
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "ABvnJMmltKyV",
"colab_type": "text"
},
"source": [
"#Regression With Fastai\n",
"\n",
"---\n",
"\n",
"**Getting Started With Regression**\n",
"\n",
"Regression With Fast.ai in 7 simple steps:\n",
"\n",
"* Importing the libraries\n",
"* Creating a TabularList\n",
"* Initialising Neural Network\n",
"* Training the model\n",
"* Evaluating the model\n",
"* A simple analysis on the predictions of the validation set\n",
"* Predicting using the network\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Mv5lcQQ9egIE"
},
"source": [
"##Importing All Major Libraries"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "NIlD79e-egIB",
"colab": {}
},
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from fastai.tabular import *"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "gtXEtYoIegH_"
},
"source": [
"**The fastai.tabular package includes all the modules that are necessary for processing tabular data.**"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ZTmAW33KefrK"
},
"source": [
"## Importing The Data"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "YlPjV7wHefrG",
"colab": {}
},
"source": [
"#Reading the datasets from excel sheet\n",
"training_set = pd.read_excel(\"Data_Train.xlsx\")\n",
"test_set = pd.read_excel(\"Data_Test.xlsx\")\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Vxa9jxUhefJr"
},
"source": [
"## Understanding The Data"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "d08a1373-bdbe-4b63-d7b1-05f207b68dcc",
"id": "yZkjxvbXefJm",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 204
}
},
"source": [
"training_set.head(5)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"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>Name</th>\n",
" <th>Location</th>\n",
" <th>Year</th>\n",
" <th>Kilometers_Driven</th>\n",
" <th>Fuel_Type</th>\n",
" <th>Transmission</th>\n",
" <th>Owner_Type</th>\n",
" <th>Mileage</th>\n",
" <th>Engine</th>\n",
" <th>Power</th>\n",
" <th>Seats</th>\n",
" <th>New_Price</th>\n",
" <th>Price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Maruti Wagon R LXI CNG</td>\n",
" <td>Mumbai</td>\n",
" <td>2010</td>\n",
" <td>72000</td>\n",
" <td>CNG</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>26.6 km/kg</td>\n",
" <td>998 CC</td>\n",
" <td>58.16 bhp</td>\n",
" <td>5.0</td>\n",
" <td>NaN</td>\n",
" <td>1.75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Hyundai Creta 1.6 CRDi SX Option</td>\n",
" <td>Pune</td>\n",
" <td>2015</td>\n",
" <td>41000</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>19.67 kmpl</td>\n",
" <td>1582 CC</td>\n",
" <td>126.2 bhp</td>\n",
" <td>5.0</td>\n",
" <td>NaN</td>\n",
" <td>12.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Honda Jazz V</td>\n",
" <td>Chennai</td>\n",
" <td>2011</td>\n",
" <td>46000</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>18.2 kmpl</td>\n",
" <td>1199 CC</td>\n",
" <td>88.7 bhp</td>\n",
" <td>5.0</td>\n",
" <td>8.61 Lakh</td>\n",
" <td>4.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Maruti Ertiga VDI</td>\n",
" <td>Chennai</td>\n",
" <td>2012</td>\n",
" <td>87000</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>20.77 kmpl</td>\n",
" <td>1248 CC</td>\n",
" <td>88.76 bhp</td>\n",
" <td>7.0</td>\n",
" <td>NaN</td>\n",
" <td>6.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Audi A4 New 2.0 TDI Multitronic</td>\n",
" <td>Coimbatore</td>\n",
" <td>2013</td>\n",
" <td>40670</td>\n",
" <td>Diesel</td>\n",
" <td>Automatic</td>\n",
" <td>Second</td>\n",
" <td>15.2 kmpl</td>\n",
" <td>1968 CC</td>\n",
" <td>140.8 bhp</td>\n",
" <td>5.0</td>\n",
" <td>NaN</td>\n",
" <td>17.74</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Name Location Year ... Seats New_Price Price\n",
"0 Maruti Wagon R LXI CNG Mumbai 2010 ... 5.0 NaN 1.75\n",
"1 Hyundai Creta 1.6 CRDi SX Option Pune 2015 ... 5.0 NaN 12.50\n",
"2 Honda Jazz V Chennai 2011 ... 5.0 8.61 Lakh 4.50\n",
"3 Maruti Ertiga VDI Chennai 2012 ... 7.0 NaN 6.00\n",
"4 Audi A4 New 2.0 TDI Multitronic Coimbatore 2013 ... 5.0 NaN 17.74\n",
"\n",
"[5 rows x 13 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 4
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "c812c285-1148-4d4f-a3e5-8de5f9fbca50",
"id": "jyevDx0mefJa",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"source": [
"\n",
"# Checking the number of rows\n",
"print(\"\\n\\nNumber of observations in the datasets :\\n\",'#' * 40)\n",
"\n",
"print(\"\\nTraining Set : \",len(training_set))\n",
"print(\"Test Set : \",len(test_set))\n",
"\n",
"# checking the number of features in the Datasets\n",
"print(\"\\n\\nNumber of features in the datasets :\\n\",'#' * 40)\n",
"\n",
"print(\"\\nTraining Set : \",len(training_set.columns))\n",
"print(\"Test Set : \",len(test_set.columns))\n",
"\n",
"# checking the features in the Datasets\n",
"print(\"\\n\\nFeatures in the datasets :\\n\",'#' * 40)\n",
"\n",
"print(\"\\nTraining Set : \", list(training_set.columns))\n",
"print(\"Test Set : \",list(test_set.columns))\n",
"\n",
"# Checking the data types of features\n",
"print(\"\\n\\nDatatypes of features in the datasets :\\n\",'#' * 40)\n",
"\n",
"print(\"\\nTraining Set : \", training_set.dtypes)\n",
"print(\"\\nTest Set : \",test_set.dtypes)\n",
"\n",
"# checking for NaNs or empty cells\n",
"print(\"\\n\\nEmpty cells or Nans in the datasets :\\n\",'#' * 40)\n",
"\n",
"print(\"\\nTraining Set : \",training_set.isnull().values.any())\n",
"print(\"\\nTest Set : \",test_set.isnull().values.any())\n",
"\n",
"# checking for NaNs or empty cells by column\n",
"print(\"\\n\\nNumber of empty cells or Nans in the datasets :\\n\",'#' * 40)\n",
"\n",
"print(\"\\nTraining Set : \",\"\\n\", training_set.isnull().sum())\n",
"print(\"\\nTest Set : \",test_set.isnull().sum())\n",
"\n",
"#Displaying dataset information\n",
"print(\"\\n\\nInfo:\\n\",'#' * 40)\n",
"\n",
"training_set.info()\n"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"\n",
"\n",
"Number of observations in the datasets :\n",
" ########################################\n",
"\n",
"Training Set : 6019\n",
"Test Set : 1234\n",
"\n",
"\n",
"Number of features in the datasets :\n",
" ########################################\n",
"\n",
"Training Set : 13\n",
"Test Set : 12\n",
"\n",
"\n",
"Features in the datasets :\n",
" ########################################\n",
"\n",
"Training Set : ['Name', 'Location', 'Year', 'Kilometers_Driven', 'Fuel_Type', 'Transmission', 'Owner_Type', 'Mileage', 'Engine', 'Power', 'Seats', 'New_Price', 'Price']\n",
"Test Set : ['Name', 'Location', 'Year', 'Kilometers_Driven', 'Fuel_Type', 'Transmission', 'Owner_Type', 'Mileage', 'Engine', 'Power', 'Seats', 'New_Price']\n",
"\n",
"\n",
"Datatypes of features in the datasets :\n",
" ########################################\n",
"\n",
"Training Set : Name object\n",
"Location object\n",
"Year int64\n",
"Kilometers_Driven int64\n",
"Fuel_Type object\n",
"Transmission object\n",
"Owner_Type object\n",
"Mileage object\n",
"Engine object\n",
"Power object\n",
"Seats float64\n",
"New_Price object\n",
"Price float64\n",
"dtype: object\n",
"\n",
"Test Set : Name object\n",
"Location object\n",
"Year int64\n",
"Kilometers_Driven int64\n",
"Fuel_Type object\n",
"Transmission object\n",
"Owner_Type object\n",
"Mileage object\n",
"Engine object\n",
"Power object\n",
"Seats float64\n",
"New_Price object\n",
"dtype: object\n",
"\n",
"\n",
"Empty cells or Nans in the datasets :\n",
" ########################################\n",
"\n",
"Training Set : True\n",
"\n",
"Test Set : True\n",
"\n",
"\n",
"Number of empty cells or Nans in the datasets :\n",
" ########################################\n",
"\n",
"Training Set : \n",
" Name 0\n",
"Location 0\n",
"Year 0\n",
"Kilometers_Driven 0\n",
"Fuel_Type 0\n",
"Transmission 0\n",
"Owner_Type 0\n",
"Mileage 2\n",
"Engine 36\n",
"Power 36\n",
"Seats 42\n",
"New_Price 5195\n",
"Price 0\n",
"dtype: int64\n",
"\n",
"Test Set : Name 0\n",
"Location 0\n",
"Year 0\n",
"Kilometers_Driven 0\n",
"Fuel_Type 0\n",
"Transmission 0\n",
"Owner_Type 0\n",
"Mileage 0\n",
"Engine 10\n",
"Power 10\n",
"Seats 11\n",
"New_Price 1052\n",
"dtype: int64\n",
"\n",
"\n",
"Info:\n",
" ########################################\n",
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 6019 entries, 0 to 6018\n",
"Data columns (total 13 columns):\n",
"Name 6019 non-null object\n",
"Location 6019 non-null object\n",
"Year 6019 non-null int64\n",
"Kilometers_Driven 6019 non-null int64\n",
"Fuel_Type 6019 non-null object\n",
"Transmission 6019 non-null object\n",
"Owner_Type 6019 non-null object\n",
"Mileage 6017 non-null object\n",
"Engine 5983 non-null object\n",
"Power 5983 non-null object\n",
"Seats 5977 non-null float64\n",
"New_Price 824 non-null object\n",
"Price 6019 non-null float64\n",
"dtypes: float64(2), int64(2), object(9)\n",
"memory usage: 611.4+ KB\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "hpL0zhrwefJY"
},
"source": [
"### Exploring Categorical features\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "9bd796e2-e67c-4a7f-aa22-4c88eaa38a47",
"id": "nurG2A5HefJV",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
}
},
"source": [
"# Non categorical Features in The dataset\n",
"training_set.select_dtypes(['int','float']).columns"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Index(['Year', 'Kilometers_Driven', 'Seats', 'Price'], dtype='object')"
]
},
"metadata": {
"tags": []
},
"execution_count": 6
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "a53f69fb-d866-414a-8c8f-482c99615c6b",
"id": "smURtTVmefJQ",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 68
}
},
"source": [
"#Categotical Features in The Dataset\n",
"training_set.select_dtypes('object').columns\n"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Index(['Name', 'Location', 'Fuel_Type', 'Transmission', 'Owner_Type',\n",
" 'Mileage', 'Engine', 'Power', 'New_Price'],\n",
" dtype='object')"
]
},
"metadata": {
"tags": []
},
"execution_count": 7
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "ab2cffa4-bcd6-4dbf-8fc5-3571f23e4873",
"id": "a7Rz9UZBefJK",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 476
}
},
"source": [
"#The Unique values in each of the categorical features \n",
"\n",
"all_brands = list(training_set.Name) + list(test_set.Name)\n",
"\n",
"all_locations = list(training_set.Location) + list(test_set.Location)\n",
"\n",
"all_fuel_types = list(training_set.Fuel_Type) + list(test_set.Fuel_Type)\n",
"\n",
"all_transmissions = list(training_set.Transmission) + list(test_set.Transmission)\n",
"\n",
"all_owner_types = list(training_set.Owner_Type) + list(test_set.Owner_Type)\n",
"\n",
"\n",
"\n",
"print(\"\\nNumber Of Unique Values In Name : \\n \", len(set(all_brands)))\n",
"#print(\"\\nThe Unique Values In Name : \\n \", set(all_brands))\n",
"\n",
"print(\"\\nNumber Of Unique Values In Location : \\n \", len(set(all_locations)))\n",
"print(\"\\nThe Unique Values In Location : \\n \", set(all_locations) )\n",
"\n",
"print(\"\\nNumber Of Unique Values In Fuel_Type : \\n \", len(set(all_fuel_types)))\n",
"print(\"\\nThe Unique Values In Fuel_Type : \\n \", set(all_fuel_types) )\n",
"\n",
"print(\"\\nNumber Of Unique Values In Transmission : \\n \", len(set(all_transmissions)))\n",
"print(\"\\nThe Unique Values In Transmission : \\n \", set(all_transmissions) )\n",
"\n",
"print(\"\\nNumber Of Unique Values In Owner_Type : \\n \", len(set(all_owner_types)))\n",
"print(\"\\nThe Unique Values In Owner_Type : \\n \", set(all_owner_types) )"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"\n",
"Number Of Unique Values In Name : \n",
" 2041\n",
"\n",
"Number Of Unique Values In Location : \n",
" 11\n",
"\n",
"The Unique Values In Location : \n",
" {'Hyderabad', 'Kolkata', 'Coimbatore', 'Delhi', 'Bangalore', 'Pune', 'Mumbai', 'Chennai', 'Jaipur', 'Kochi', 'Ahmedabad'}\n",
"\n",
"Number Of Unique Values In Fuel_Type : \n",
" 5\n",
"\n",
"The Unique Values In Fuel_Type : \n",
" {'Electric', 'CNG', 'LPG', 'Petrol', 'Diesel'}\n",
"\n",
"Number Of Unique Values In Transmission : \n",
" 2\n",
"\n",
"The Unique Values In Transmission : \n",
" {'Automatic', 'Manual'}\n",
"\n",
"Number Of Unique Values In Owner_Type : \n",
" 4\n",
"\n",
"The Unique Values In Owner_Type : \n",
" {'First', 'Fourth & Above', 'Second', 'Third'}\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "KzTZDzoRedSA"
},
"source": [
"## Feature Generation And Dataset Restructuring"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "ajipRklVedR9",
"colab": {}
},
"source": [
"#Based on the information gathered from the data, lets simplify and restructure it.\n",
"\n",
"def restructure(data):\n",
" \n",
" names = list(data.Name)\n",
" \n",
" brand = []\n",
" model = []\n",
" \n",
" #Splitting The Column 'Name'\n",
" for i in range(len(names)):\n",
" try:\n",
" brand.append(names[i].split(\" \")[0])\n",
" try:\n",
" model.append(\" \".join(names[i].split(\" \")[1:]).strip())\n",
" except:\n",
" pass\n",
" except:\n",
" print(\"ERR ! - \", names[i], \"@\" , i)\n",
" \n",
" \n",
" #Cleaning Mileage Column\n",
" mileage = list(data.Mileage)\n",
" \n",
" for i in range(len(mileage)):\n",
" try :\n",
" mileage[i] = float(mileage[i].split(\" \")[0].strip())\n",
" except:\n",
" mileage[i] = np.nan\n",
" \n",
" #Cleaning Engine Column \n",
" engine = list(data.Engine)\n",
" for i in range(len(engine)):\n",
" try :\n",
" engine[i] = int(engine[i].split(\" \")[0].strip())\n",
" except:\n",
" engine[i] = np.nan\n",
" \n",
" #Cleaning Power Columns\n",
" power = list(data.Power)\n",
" for i in range(len(power)):\n",
" try :\n",
" power[i] = float(power[i].split(\" \")[0].strip())\n",
" except:\n",
" power[i] = np.nan\n",
" \n",
" #Cleaning New_Price\n",
" data['New_Price'].fillna(0, inplace = True)\n",
" \n",
" newp = list(data['New_Price'])\n",
" \n",
" for i in range(len(newp)):\n",
" if newp[i] == 0:\n",
" newp[i] = float(newp[i])\n",
" continue\n",
" elif 'Cr' in newp[i]:\n",
" newp[i] = float(newp[i].split()[0].strip()) * 100 \n",
" elif 'Lakh' in newp[i]:\n",
" newp[i] = float(newp[i].split()[0].strip())\n",
" \n",
" \n",
" #Re-ordering the columns\n",
"\n",
" restructured = pd.DataFrame({'Brand': brand,\n",
" 'Model':model,\n",
" 'Location': data['Location'], \n",
" 'Year':data['Year'] , \n",
" 'Kilometers_Driven':data['Kilometers_Driven'],\n",
" 'Fuel_Type':data['Fuel_Type'],\n",
" 'Transmission':data['Transmission'],\n",
" 'Owner_Type':data['Owner_Type'],\n",
" 'Mileage':mileage,\n",
" 'Engine':engine,\n",
" 'Power':power,\n",
" 'Seats':data['Seats'],\n",
" 'New_Price':newp\n",
" })\n",
"\n",
" #If the dataset passed is training set include the Price column\n",
" if 'Price' in data.columns:\n",
" restructured['Price'] = data['Price']\n",
" return restructured\n",
" \n",
" \n",
" else:\n",
" return restructured\n",
" "
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "2nEwUvr7edR8"
},
"source": [
"**Summary:**\n",
"\n",
"The data is is restructured in the following ways:\n",
"1. The Name column in the original dataset is split in to two features, Brand and Model.\n",
"1. The Mileage column is cleaned to have float values.\n",
"1. The Engine column is cleaned to have integer values.\n",
"2. The Power column is cleaned to have integer values.\n",
"2. The New_Price column is cleaned to remove nulls and correct the units.\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "Zow6LouDedR2",
"colab": {}
},
"source": [
"#Restructuring Training and Test sets\n",
"train_data = restructure(training_set)\n",
"test_data = restructure(test_set)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "25e9c2a4-5375-4089-b582-583fd8366905",
"id": "wi7gg6ljedRt",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
}
},
"source": [
"#the dimensions of the training set\n",
"train_data.shape"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(6019, 14)"
]
},
"metadata": {
"tags": []
},
"execution_count": 11
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "721cc3f0-40a0-4950-a2cf-a2bff0479e23",
"id": "6d4vq7CbedRm",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
}
},
"source": [
"#the dimensions of the test set\n",
"test_data.shape"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(1234, 13)"
]
},
"metadata": {
"tags": []
},
"execution_count": 12
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "ee486914-1185-4d2d-cefb-bf70d71f90f1",
"id": "MTj9MSHDedRd",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 204
}
},
"source": [
"#Top 5 rows of the training set\n",
"train_data.head(5)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"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>Brand</th>\n",
" <th>Model</th>\n",
" <th>Location</th>\n",
" <th>Year</th>\n",
" <th>Kilometers_Driven</th>\n",
" <th>Fuel_Type</th>\n",
" <th>Transmission</th>\n",
" <th>Owner_Type</th>\n",
" <th>Mileage</th>\n",
" <th>Engine</th>\n",
" <th>Power</th>\n",
" <th>Seats</th>\n",
" <th>New_Price</th>\n",
" <th>Price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Maruti</td>\n",
" <td>Wagon R LXI CNG</td>\n",
" <td>Mumbai</td>\n",
" <td>2010</td>\n",
" <td>72000</td>\n",
" <td>CNG</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>26.60</td>\n",
" <td>998.0</td>\n",
" <td>58.16</td>\n",
" <td>5.0</td>\n",
" <td>0.00</td>\n",
" <td>1.75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Hyundai</td>\n",
" <td>Creta 1.6 CRDi SX Option</td>\n",
" <td>Pune</td>\n",
" <td>2015</td>\n",
" <td>41000</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>19.67</td>\n",
" <td>1582.0</td>\n",
" <td>126.20</td>\n",
" <td>5.0</td>\n",
" <td>0.00</td>\n",
" <td>12.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Honda</td>\n",
" <td>Jazz V</td>\n",
" <td>Chennai</td>\n",
" <td>2011</td>\n",
" <td>46000</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>18.20</td>\n",
" <td>1199.0</td>\n",
" <td>88.70</td>\n",
" <td>5.0</td>\n",
" <td>8.61</td>\n",
" <td>4.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Maruti</td>\n",
" <td>Ertiga VDI</td>\n",
" <td>Chennai</td>\n",
" <td>2012</td>\n",
" <td>87000</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>20.77</td>\n",
" <td>1248.0</td>\n",
" <td>88.76</td>\n",
" <td>7.0</td>\n",
" <td>0.00</td>\n",
" <td>6.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Audi</td>\n",
" <td>A4 New 2.0 TDI Multitronic</td>\n",
" <td>Coimbatore</td>\n",
" <td>2013</td>\n",
" <td>40670</td>\n",
" <td>Diesel</td>\n",
" <td>Automatic</td>\n",
" <td>Second</td>\n",
" <td>15.20</td>\n",
" <td>1968.0</td>\n",
" <td>140.80</td>\n",
" <td>5.0</td>\n",
" <td>0.00</td>\n",
" <td>17.74</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Brand Model Location ... Seats New_Price Price\n",
"0 Maruti Wagon R LXI CNG Mumbai ... 5.0 0.00 1.75\n",
"1 Hyundai Creta 1.6 CRDi SX Option Pune ... 5.0 0.00 12.50\n",
"2 Honda Jazz V Chennai ... 5.0 8.61 4.50\n",
"3 Maruti Ertiga VDI Chennai ... 7.0 0.00 6.00\n",
"4 Audi A4 New 2.0 TDI Multitronic Coimbatore ... 5.0 0.00 17.74\n",
"\n",
"[5 rows x 14 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"outputId": "1f09b118-e32a-4465-8914-5523a492f2dc",
"id": "0AeGSHZWedRR",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 204
}
},
"source": [
"#Top 5 rows of the test set\n",
"test_data.head()"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"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>Brand</th>\n",
" <th>Model</th>\n",
" <th>Location</th>\n",
" <th>Year</th>\n",
" <th>Kilometers_Driven</th>\n",
" <th>Fuel_Type</th>\n",
" <th>Transmission</th>\n",
" <th>Owner_Type</th>\n",
" <th>Mileage</th>\n",
" <th>Engine</th>\n",
" <th>Power</th>\n",
" <th>Seats</th>\n",
" <th>New_Price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Maruti</td>\n",
" <td>Alto K10 LXI CNG</td>\n",
" <td>Delhi</td>\n",
" <td>2014</td>\n",
" <td>40929</td>\n",
" <td>CNG</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>32.26</td>\n",
" <td>998.0</td>\n",
" <td>58.20</td>\n",
" <td>4.0</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Maruti</td>\n",
" <td>Alto 800 2016-2019 LXI</td>\n",
" <td>Coimbatore</td>\n",
" <td>2013</td>\n",
" <td>54493</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>Second</td>\n",
" <td>24.70</td>\n",
" <td>796.0</td>\n",
" <td>47.30</td>\n",
" <td>5.0</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Toyota</td>\n",
" <td>Innova Crysta Touring Sport 2.4 MT</td>\n",
" <td>Mumbai</td>\n",
" <td>2017</td>\n",
" <td>34000</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>13.68</td>\n",
" <td>2393.0</td>\n",
" <td>147.80</td>\n",
" <td>7.0</td>\n",
" <td>25.27</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Toyota</td>\n",
" <td>Etios Liva GD</td>\n",
" <td>Hyderabad</td>\n",
" <td>2012</td>\n",
" <td>139000</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>23.59</td>\n",
" <td>1364.0</td>\n",
" <td>NaN</td>\n",
" <td>5.0</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Hyundai</td>\n",
" <td>i20 Magna</td>\n",
" <td>Mumbai</td>\n",
" <td>2014</td>\n",
" <td>29000</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>18.50</td>\n",
" <td>1197.0</td>\n",
" <td>82.85</td>\n",
" <td>5.0</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Brand Model ... Seats New_Price\n",
"0 Maruti Alto K10 LXI CNG ... 4.0 0.00\n",
"1 Maruti Alto 800 2016-2019 LXI ... 5.0 0.00\n",
"2 Toyota Innova Crysta Touring Sport 2.4 MT ... 7.0 25.27\n",
"3 Toyota Etios Liva GD ... 5.0 0.00\n",
"4 Hyundai i20 Magna ... 5.0 0.00\n",
"\n",
"[5 rows x 13 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 14
}
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "lltV1jSW1j4F"
},
"source": [
"## Regression With Fast.ai\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "6yXVii4w1j38"
},
"source": [
"###Creating A TabularList"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xV1y3p9E6N_2",
"colab_type": "text"
},
"source": [
"TabularList in fastai is the basic ItemList for any kind of tabular data.It is a class to create a list of inputs in items for tabular data. \n",
"\n",
"Main Arguments:\n",
"\n",
"cat_names : The categorical features in the data.\n",
"\n",
"cont_names : The continuous features in the data.\n",
"\n",
"procs : A liat of transformations to be applies to the data such as FillMissing, Categorify, Normalize etc."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "E1-0qnbH1j32",
"colab": {}
},
"source": [
"#Defining the keyword arguments for fastai's TabularList\n",
"\n",
"#Path / default location for saving/loading models\n",
"path = ''\n",
"\n",
"#The dependent variable/target\n",
"dep_var = 'Price'\n",
"\n",
"#The list of categorical features in the dataset\n",
"cat_names = ['Brand', 'Model', 'Location', 'Fuel_Type', 'Transmission', 'Owner_Type'] \n",
"\n",
"#The list of continuous features in the dataset\n",
"#Exclude the Dependent variable 'Price'\n",
"cont_names =['Year', 'Kilometers_Driven', 'Mileage', 'Engine', 'Power', 'Seats', 'New_Price'] \n",
"\n",
"#List of Processes/transforms to be applied to the dataset\n",
"procs = [FillMissing, Categorify, Normalize]\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "4e48KbHy1j30",
"colab": {}
},
"source": [
"#Start index for creating a validation set from train_data\n",
"start_indx = len(train_data) - int(len(train_data) * 0.2)\n",
"\n",
"#End index for creating a validation set from train_data\n",
"end_indx = len(train_data)\n",
"\n",
"\n",
"#TabularList for Validation\n",
"val = (TabularList.from_df(train_data.iloc[start_indx:end_indx].copy(), path=path, cat_names=cat_names, cont_names=cont_names))\n",
"\n",
"test = (TabularList.from_df(test_data, path=path, cat_names=cat_names, cont_names=cont_names, procs=procs))\n",
"\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "Vt18jvfP1j3u",
"colab": {}
},
"source": [
"#TabularList for training\n",
"data = (TabularList.from_df(train_data, path=path, cat_names=cat_names, cont_names=cont_names, procs=procs)\n",
" .split_by_idx(list(range(start_indx,end_indx)))\n",
" .label_from_df(cols=dep_var)\n",
" .add_test(test)\n",
" .databunch())"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "WHGNuBzM7sgT",
"colab_type": "text"
},
"source": [
"**Summary:**\n",
"\n",
"1. Initializing/Setting The parameters for TabularList such as path, dep_var, cat_names, cont_names and procs.\n",
"1. Setting the index for Validation set. The start index and End index are set in such a away that it takes the last 20% data from the training set for validation.\n",
"2. Creating TabularList for Validation set from train_data. \n",
"2. Creating TabularList for Test set from test_data. \n",
"1. Creating a DataBunch for the network.DataBunch is a class that binds train_dl,valid_dl and test_dl in a data object.\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "f5syfNX71j3r",
"outputId": "2ffdab91-8eb1-4d9d-b275-ae2aad39c1de",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 359
}
},
"source": [
"#Display the data batch\n",
"data.show_batch(rows = 10)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Brand</th>\n",
" <th>Model</th>\n",
" <th>Location</th>\n",
" <th>Fuel_Type</th>\n",
" <th>Transmission</th>\n",
" <th>Owner_Type</th>\n",
" <th>Mileage_na</th>\n",
" <th>Engine_na</th>\n",
" <th>Power_na</th>\n",
" <th>Seats_na</th>\n",
" <th>Year</th>\n",
" <th>Kilometers_Driven</th>\n",
" <th>Mileage</th>\n",
" <th>Engine</th>\n",
" <th>Power</th>\n",
" <th>Seats</th>\n",
" <th>New_Price</th>\n",
" <th>target</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Nissan</td>\n",
" <td>Micra Active XV</td>\n",
" <td>Pune</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>1.4350</td>\n",
" <td>-0.3498</td>\n",
" <td>0.3534</td>\n",
" <td>-0.7136</td>\n",
" <td>-0.8759</td>\n",
" <td>-0.3457</td>\n",
" <td>0.2942</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Maruti</td>\n",
" <td>Zen Estilo 1.1 LXI BSIII</td>\n",
" <td>Bangalore</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>Second</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-1.9544</td>\n",
" <td>0.0080</td>\n",
" <td>0.0264</td>\n",
" <td>-0.9445</td>\n",
" <td>-0.9338</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>1.65</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Maruti</td>\n",
" <td>Swift LDI SP Limited Edition</td>\n",
" <td>Hyderabad</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>0.8188</td>\n",
" <td>-0.0453</td>\n",
" <td>1.5627</td>\n",
" <td>-0.6294</td>\n",
" <td>-0.7433</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>6.25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Renault</td>\n",
" <td>Duster 110PS Diesel RxZ</td>\n",
" <td>Delhi</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-0.1056</td>\n",
" <td>0.0776</td>\n",
" <td>0.2042</td>\n",
" <td>-0.2704</td>\n",
" <td>-0.0868</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>4.75</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Maruti</td>\n",
" <td>SX4 ZDI</td>\n",
" <td>Chennai</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>Third</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-0.7219</td>\n",
" <td>0.2068</td>\n",
" <td>0.7507</td>\n",
" <td>-0.6294</td>\n",
" <td>-0.4612</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>3.5</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Maruti</td>\n",
" <td>Zen Estilo LXI BS IV</td>\n",
" <td>Mumbai</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-1.3381</td>\n",
" <td>-0.1212</td>\n",
" <td>0.2020</td>\n",
" <td>-1.0507</td>\n",
" <td>-0.8747</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>1.46</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Hyundai</td>\n",
" <td>i10 Sportz 1.2</td>\n",
" <td>Bangalore</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-1.0300</td>\n",
" <td>-0.3001</td>\n",
" <td>0.5004</td>\n",
" <td>-0.7153</td>\n",
" <td>-0.6499</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>3.45</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Honda</td>\n",
" <td>City i-VTEC V</td>\n",
" <td>Kolkata</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-0.7219</td>\n",
" <td>-0.2646</td>\n",
" <td>-0.1492</td>\n",
" <td>-0.2097</td>\n",
" <td>0.0818</td>\n",
" <td>-0.3457</td>\n",
" <td>0.6630</td>\n",
" <td>3.87</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Mahindra</td>\n",
" <td>XUV500 W6 2WD</td>\n",
" <td>Coimbatore</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>0.8188</td>\n",
" <td>0.0373</td>\n",
" <td>-0.6540</td>\n",
" <td>0.9396</td>\n",
" <td>0.5144</td>\n",
" <td>2.1244</td>\n",
" <td>-0.2485</td>\n",
" <td>11.05</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Toyota</td>\n",
" <td>Innova 2.5 G (Diesel) 7 Seater BS IV</td>\n",
" <td>Hyderabad</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-0.4138</td>\n",
" <td>0.7137</td>\n",
" <td>-1.1171</td>\n",
" <td>1.4705</td>\n",
" <td>-0.2478</td>\n",
" <td>2.1244</td>\n",
" <td>-0.2485</td>\n",
" <td>9.6</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Nq-MnASS1j3q"
},
"source": [
"###Initializing Neural Network\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "OJlEk4gi1j3n",
"colab": {}
},
"source": [
"#Initializing the network\n",
"learn = tabular_learner(data, layers=[300,200, 100, 50], metrics= [rmse,r2_score])\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "iOTLWeZk1j3l"
},
"source": [
"\n",
"The above line of code will initialize a neural network with 4 layers and the number of nodes in each layer as 300,200, 100 and 50 respectively. \n",
"\n",
"The network will use two primary metrics for evaluation:\n",
"\n",
"* Root Mean Squared Error(RMSE)\n",
"* R-Squared\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "hIDubrn63-VS",
"colab_type": "code",
"outputId": "a096e3ec-ac14-4e19-8e25-66384d49750a",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"source": [
"#Show the complete Summary of the model\n",
"learn.summary"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<bound method model_summary of Learner(data=TabularDataBunch;\n",
"\n",
"Train: LabelList (4816 items)\n",
"x: TabularList\n",
"Brand Maruti; Model Wagon R LXI CNG; Location Mumbai; Fuel_Type CNG; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year -1.0300; Kilometers_Driven 0.1273; Mileage 1.8700; Engine -1.0507; Power -1.0451; Seats -0.3457; New_Price -0.2485; ,Brand Hyundai; Model Creta 1.6 CRDi SX Option; Location Pune; Fuel_Type Diesel; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year 0.5106; Kilometers_Driven -0.1808; Mileage 0.3490; Engine -0.0665; Power 0.2514; Seats -0.3457; New_Price -0.2485; ,Brand Honda; Model Jazz V; Location Chennai; Fuel_Type Petrol; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year -0.7219; Kilometers_Driven -0.1311; Mileage 0.0264; Engine -0.7119; Power -0.4631; Seats -0.3457; New_Price 0.4200; ,Brand Maruti; Model Ertiga VDI; Location Chennai; Fuel_Type Diesel; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year -0.4138; Kilometers_Driven 0.2764; Mileage 0.5904; Engine -0.6294; Power -0.4620; Seats 2.1244; New_Price -0.2485; ,Brand Audi; Model A4 New 2.0 TDI Multitronic; Location Coimbatore; Fuel_Type Diesel; Transmission Automatic; Owner_Type Second; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year -0.1056; Kilometers_Driven -0.1841; Mileage -0.6321; Engine 0.5840; Power 0.5296; Seats -0.3457; New_Price -0.2485; \n",
"y: FloatList\n",
"1.75,12.5,4.5,6.0,17.74\n",
"Path: .;\n",
"\n",
"Valid: LabelList (1203 items)\n",
"x: TabularList\n",
"Brand BMW; Model #na#; Location Delhi; Fuel_Type Petrol; Transmission Automatic; Owner_Type Second; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year -2.2625; Kilometers_Driven -0.1112; Mileage -1.4178; Engine 2.2879; Power 3.6776; Seats -0.3457; New_Price -0.2485; ,Brand Hyundai; Model Elantra CRDi SX; Location Coimbatore; Fuel_Type Diesel; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year 1.7431; Kilometers_Driven -0.1722; Mileage 1.0140; Engine -0.0665; Power 0.2514; Seats -0.3457; New_Price -0.2485; ,Brand Tata; Model Sumo EX; Location Coimbatore; Fuel_Type Diesel; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year 0.5106; Kilometers_Driven 0.2558; Mileage -0.6101; Engine 2.2491; Power -0.5565; Seats 2.1244; New_Price -0.2485; ,Brand Datsun; Model #na#; Location Kolkata; Fuel_Type Petrol; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year 0.8188; Kilometers_Driven -0.4392; Mileage 1.0140; Engine -1.3861; Power -1.1312; Seats -0.3457; New_Price 0.0605; ,Brand BMW; Model X5 xDrive 30d; Location Chennai; Fuel_Type Diesel; Transmission Automatic; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year -1.3381; Kilometers_Driven 0.5049; Mileage -1.4002; Engine 2.3115; Power 2.5152; Seats -0.3457; New_Price -0.2485; \n",
"y: FloatList\n",
"6.99,15.57,5.29,2.25,20.0\n",
"Path: .;\n",
"\n",
"Test: LabelList (1234 items)\n",
"x: TabularList\n",
"Brand Maruti; Model #na#; Location Delhi; Fuel_Type CNG; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year 0.2025; Kilometers_Driven -0.1815; Mileage 3.1122; Engine -1.0507; Power -1.0443; Seats -1.5807; New_Price -0.2485; ,Brand Maruti; Model Alto 800 2016-2019 LXI; Location Coimbatore; Fuel_Type Petrol; Transmission Manual; Owner_Type Second; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year -0.1056; Kilometers_Driven -0.0467; Mileage 1.4530; Engine -1.3911; Power -1.2520; Seats -0.3457; New_Price -0.2485; ,Brand Toyota; Model #na#; Location Mumbai; Fuel_Type Diesel; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year 1.1269; Kilometers_Driven -0.2504; Mileage -0.9657; Engine 1.3003; Power 0.6630; Seats 2.1244; New_Price 1.7134; ,Brand Toyota; Model Etios Liva GD; Location Hyderabad; Fuel_Type Diesel; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na True; Seats_na False; Year -0.4138; Kilometers_Driven 0.7932; Mileage 1.2094; Engine -0.4339; Power -0.2747; Seats -0.3457; New_Price -0.2485; ,Brand Hyundai; Model i20 Magna; Location Mumbai; Fuel_Type Petrol; Transmission Manual; Owner_Type First; Mileage_na False; Engine_na False; Power_na False; Seats_na False; Year 0.2025; Kilometers_Driven -0.3001; Mileage 0.0922; Engine -0.7153; Power -0.5746; Seats -0.3457; New_Price -0.2485; \n",
"y: EmptyLabelList\n",
",,,,\n",
"Path: ., model=TabularModel(\n",
" (embeds): ModuleList(\n",
" (0): Embedding(29, 11)\n",
" (1): Embedding(1696, 103)\n",
" (2): Embedding(12, 6)\n",
" (3): Embedding(6, 4)\n",
" (4): Embedding(3, 3)\n",
" (5): Embedding(5, 4)\n",
" (6): Embedding(3, 3)\n",
" (7): Embedding(3, 3)\n",
" (8): Embedding(3, 3)\n",
" (9): Embedding(3, 3)\n",
" )\n",
" (emb_drop): Dropout(p=0.0, inplace=False)\n",
" (bn_cont): BatchNorm1d(7, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (layers): Sequential(\n",
" (0): Linear(in_features=150, out_features=300, bias=True)\n",
" (1): ReLU(inplace=True)\n",
" (2): BatchNorm1d(300, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (3): Linear(in_features=300, out_features=200, bias=True)\n",
" (4): ReLU(inplace=True)\n",
" (5): BatchNorm1d(200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (6): Linear(in_features=200, out_features=100, bias=True)\n",
" (7): ReLU(inplace=True)\n",
" (8): BatchNorm1d(100, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (9): Linear(in_features=100, out_features=50, bias=True)\n",
" (10): ReLU(inplace=True)\n",
" (11): BatchNorm1d(50, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (12): Linear(in_features=50, out_features=1, bias=True)\n",
" )\n",
"), opt_func=functools.partial(<class 'torch.optim.adam.Adam'>, betas=(0.9, 0.99)), loss_func=FlattenedLoss of MSELoss(), metrics=[<function root_mean_squared_error at 0x7fe2cd330268>, <function r2_score at 0x7fe2cd330400>], true_wd=True, bn_wd=True, wd=0.01, train_bn=True, path=PosixPath('.'), model_dir='models', callback_fns=[functools.partial(<class 'fastai.basic_train.Recorder'>, add_time=True, silent=False)], callbacks=[], layer_groups=[Sequential(\n",
" (0): Embedding(29, 11)\n",
" (1): Embedding(1696, 103)\n",
" (2): Embedding(12, 6)\n",
" (3): Embedding(6, 4)\n",
" (4): Embedding(3, 3)\n",
" (5): Embedding(5, 4)\n",
" (6): Embedding(3, 3)\n",
" (7): Embedding(3, 3)\n",
" (8): Embedding(3, 3)\n",
" (9): Embedding(3, 3)\n",
" (10): Dropout(p=0.0, inplace=False)\n",
" (11): BatchNorm1d(7, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (12): Linear(in_features=150, out_features=300, bias=True)\n",
" (13): ReLU(inplace=True)\n",
" (14): BatchNorm1d(300, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (15): Linear(in_features=300, out_features=200, bias=True)\n",
" (16): ReLU(inplace=True)\n",
" (17): BatchNorm1d(200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (18): Linear(in_features=200, out_features=100, bias=True)\n",
" (19): ReLU(inplace=True)\n",
" (20): BatchNorm1d(100, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (21): Linear(in_features=100, out_features=50, bias=True)\n",
" (22): ReLU(inplace=True)\n",
" (23): BatchNorm1d(50, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (24): Linear(in_features=50, out_features=1, bias=True)\n",
")], add_time=True, silent=False)>"
]
},
"metadata": {
"tags": []
},
"execution_count": 20
}
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "otdALDmE1j3k"
},
"source": [
"###Training The Network"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h2vWHWFyU34D",
"colab_type": "code",
"outputId": "160692fd-21fb-4427-e927-785ca35e18ee",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
}
},
"source": [
"learn.lr_find(start_lr = 1e-05,end_lr = 1e+05, num_it = 100)\n",
"learn.recorder.plot()"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "stream",
"text": [
"LR Finder is complete, type {learner_name}.recorder.plot() to see the graph.\n"
],
"name": "stdout"
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xd8VFXex/HPL51UShJKAoSOSCd0\nVFDXtSMW7F1x7a5uU59n3fKwa3ftChZkV1FWseC6CioIUo3SISBNICA9hBJSyHn+mEEjDiFlJpOZ\nfN+v17yYOX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D6g/AGueZ6uK3ZnYanvsI9AN6An3M7MRjfZ6IL+E6\nWZ/IkU4FupSbeTPZOyNnCvCad34pB0SXW2eqc678PQDmO+c2AZjZQiAL+PKIzynGcxMl8Exi9wvv\n84H8OLf/G8CjR6mzgXfbGcAKPPcKADDgb94f+zLv+019rH+a97HA+zoRT2CE4k16JMgUEFJfRAAD\nnHMHyzea2TPANOfcCO/+/Onl3t5/xDaKyj0/hO9/PyXuxwN7R1umIoXOuZ7mmXL+E+BW4CngciAN\n6OOcKzGz9UCcj/UN+Ltz7sUqfq7Iz2gXk9QXU4DbD78ws8PTNKfw45TK1wTw8+fi2bUFcMmxFnae\nmWDvAO4xsyg8dW7zhsMwoLV30b1AUrlVPwGu846OMLMMM0v303eQekYBIeEo3sw2lXvcjefHNtt7\n4HY58Cvvsg8DfzezBQR2RH0XcLeZLcZzE5k9x1rBObcAz4y5l+K570a2mS3BMw10rneZncAs72mx\njzjnpuDZhTXHu+zb/DRARCpNp7mK1ALvLqNC55wzs0uAS51zw4+1nkgw6RiESO3oAzzjPfMoH8/9\nAETqNI0gRETEJx2DEBERnxQQIiLikwJCRER8UkCIiIhPCggREfFJASEiIj79P40rHaU+hvrTAAAA\nAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "H_6pgTxddHEj",
"colab_type": "text"
},
"source": [
"Learning rate is a hyper-parameter that controls how much the weights of the network is being adjusted with respect the loss gradient.\n",
"\n",
"The lr_find method helps explore the learning rate in a specified range. The graph shows the deviation in loss with respect to the learning rate."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "Am3r-2zR1j3U",
"outputId": "66b12617-06cf-4701-94e4-7fe1743071ed",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 824
}
},
"source": [
"#Fitting data and training the network\n",
"learn.fit_one_cycle(25)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>root_mean_squared_error</th>\n",
" <th>r2_score</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>170.930954</td>\n",
" <td>161.123108</td>\n",
" <td>12.526302</td>\n",
" <td>-0.330882</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>152.859070</td>\n",
" <td>149.356277</td>\n",
" <td>12.099945</td>\n",
" <td>-0.264155</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>119.679787</td>\n",
" <td>96.389923</td>\n",
" <td>9.771078</td>\n",
" <td>0.140050</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>82.348785</td>\n",
" <td>55.138988</td>\n",
" <td>7.370564</td>\n",
" <td>0.508471</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>48.968166</td>\n",
" <td>23.842108</td>\n",
" <td>4.833325</td>\n",
" <td>0.789911</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <td>26.032892</td>\n",
" <td>17.158106</td>\n",
" <td>3.929134</td>\n",
" <td>0.869249</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6</td>\n",
" <td>17.878710</td>\n",
" <td>9.110335</td>\n",
" <td>2.786590</td>\n",
" <td>0.926840</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7</td>\n",
" <td>13.887877</td>\n",
" <td>9.249630</td>\n",
" <td>2.722911</td>\n",
" <td>0.934174</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8</td>\n",
" <td>13.685216</td>\n",
" <td>14.990489</td>\n",
" <td>3.492407</td>\n",
" <td>0.894274</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9</td>\n",
" <td>11.866707</td>\n",
" <td>9.405542</td>\n",
" <td>2.823769</td>\n",
" <td>0.926297</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10</td>\n",
" <td>11.612128</td>\n",
" <td>9.532630</td>\n",
" <td>2.771031</td>\n",
" <td>0.931684</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11</td>\n",
" <td>11.271067</td>\n",
" <td>10.023697</td>\n",
" <td>2.850357</td>\n",
" <td>0.928993</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>12</td>\n",
" <td>12.695855</td>\n",
" <td>9.955544</td>\n",
" <td>2.761512</td>\n",
" <td>0.933563</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>13</td>\n",
" <td>12.834098</td>\n",
" <td>12.585591</td>\n",
" <td>3.112505</td>\n",
" <td>0.916915</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>14</td>\n",
" <td>11.626652</td>\n",
" <td>11.697491</td>\n",
" <td>2.959678</td>\n",
" <td>0.923977</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>15</td>\n",
" <td>11.730012</td>\n",
" <td>18.769026</td>\n",
" <td>3.915838</td>\n",
" <td>0.875023</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>16</td>\n",
" <td>13.120429</td>\n",
" <td>12.952336</td>\n",
" <td>3.194207</td>\n",
" <td>0.913939</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>17</td>\n",
" <td>10.109412</td>\n",
" <td>15.637222</td>\n",
" <td>3.527203</td>\n",
" <td>0.897277</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>18</td>\n",
" <td>9.204473</td>\n",
" <td>12.849992</td>\n",
" <td>3.102328</td>\n",
" <td>0.916921</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>19</td>\n",
" <td>7.052763</td>\n",
" <td>11.737025</td>\n",
" <td>2.987463</td>\n",
" <td>0.920450</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>20</td>\n",
" <td>7.344553</td>\n",
" <td>12.277870</td>\n",
" <td>3.056447</td>\n",
" <td>0.917726</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>21</td>\n",
" <td>6.613494</td>\n",
" <td>12.115734</td>\n",
" <td>2.985884</td>\n",
" <td>0.922169</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>22</td>\n",
" <td>6.371452</td>\n",
" <td>12.402617</td>\n",
" <td>2.996723</td>\n",
" <td>0.920773</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>23</td>\n",
" <td>6.860789</td>\n",
" <td>12.873620</td>\n",
" <td>3.077043</td>\n",
" <td>0.917000</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" <tr>\n",
" <td>24</td>\n",
" <td>7.468849</td>\n",
" <td>12.758644</td>\n",
" <td>3.077939</td>\n",
" <td>0.916618</td>\n",
" <td>00:01</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "-nj8YKKD1j3R"
},
"source": [
"**The above line trains the network for 25 epochs.**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jsxdqeB9hEwd",
"colab_type": "text"
},
"source": [
"### Evaluating Performance"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "Bbzeli2I1j3C",
"outputId": "a70ea551-1888-48cc-b8a2-e1a20d5385b4",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 204
}
},
"source": [
"#Display Predictions On Training Data\n",
"learn.show_results(ds_type=DatasetType.Train,rows = 5)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Brand</th>\n",
" <th>Model</th>\n",
" <th>Location</th>\n",
" <th>Fuel_Type</th>\n",
" <th>Transmission</th>\n",
" <th>Owner_Type</th>\n",
" <th>Mileage_na</th>\n",
" <th>Engine_na</th>\n",
" <th>Power_na</th>\n",
" <th>Seats_na</th>\n",
" <th>Year</th>\n",
" <th>Kilometers_Driven</th>\n",
" <th>Mileage</th>\n",
" <th>Engine</th>\n",
" <th>Power</th>\n",
" <th>Seats</th>\n",
" <th>New_Price</th>\n",
" <th>target</th>\n",
" <th>prediction</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Volkswagen</td>\n",
" <td>Polo Petrol Comfortline 1.2L</td>\n",
" <td>Kochi</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-0.4138</td>\n",
" <td>-0.0634</td>\n",
" <td>-0.3533</td>\n",
" <td>-0.7136</td>\n",
" <td>-0.7452</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>3.82</td>\n",
" <td>[4.371329]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Toyota</td>\n",
" <td>Corolla Altis G MT</td>\n",
" <td>Kolkata</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>0.2025</td>\n",
" <td>-0.3199</td>\n",
" <td>-0.8340</td>\n",
" <td>0.2975</td>\n",
" <td>0.4769</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>7.95</td>\n",
" <td>[8.259411]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Maruti</td>\n",
" <td>Wagon R VXI</td>\n",
" <td>Mumbai</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>0.2025</td>\n",
" <td>-0.1547</td>\n",
" <td>0.9701</td>\n",
" <td>-1.0507</td>\n",
" <td>-0.8759</td>\n",
" <td>-0.3457</td>\n",
" <td>0.1871</td>\n",
" <td>3.16</td>\n",
" <td>[3.749952]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Hyundai</td>\n",
" <td>Accent CRDi</td>\n",
" <td>Kochi</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-2.2625</td>\n",
" <td>1.0072</td>\n",
" <td>-1.0930</td>\n",
" <td>-0.2165</td>\n",
" <td>-0.5908</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>1.8</td>\n",
" <td>[2.474023]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Honda</td>\n",
" <td>Amaze S i-Dtech</td>\n",
" <td>Ahmedabad</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>0.2025</td>\n",
" <td>0.0209</td>\n",
" <td>1.6944</td>\n",
" <td>-0.2080</td>\n",
" <td>-0.2745</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>4.35</td>\n",
" <td>[5.159999]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "Ho9s8tIr1j26",
"outputId": "883dea64-3738-4fa3-8ac5-578af8bfb27a",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 204
}
},
"source": [
"#Display Predictions On Validation Data\n",
"learn.show_results(ds_type=DatasetType.Valid)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Brand</th>\n",
" <th>Model</th>\n",
" <th>Location</th>\n",
" <th>Fuel_Type</th>\n",
" <th>Transmission</th>\n",
" <th>Owner_Type</th>\n",
" <th>Mileage_na</th>\n",
" <th>Engine_na</th>\n",
" <th>Power_na</th>\n",
" <th>Seats_na</th>\n",
" <th>Year</th>\n",
" <th>Kilometers_Driven</th>\n",
" <th>Mileage</th>\n",
" <th>Engine</th>\n",
" <th>Power</th>\n",
" <th>Seats</th>\n",
" <th>New_Price</th>\n",
" <th>target</th>\n",
" <th>prediction</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>BMW</td>\n",
" <td>#na#</td>\n",
" <td>Delhi</td>\n",
" <td>Petrol</td>\n",
" <td>Automatic</td>\n",
" <td>Second</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-2.2625</td>\n",
" <td>-0.1112</td>\n",
" <td>-1.4178</td>\n",
" <td>2.2879</td>\n",
" <td>3.6776</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>6.99</td>\n",
" <td>[10.922736]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Hyundai</td>\n",
" <td>Elantra CRDi SX</td>\n",
" <td>Coimbatore</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>1.7431</td>\n",
" <td>-0.1722</td>\n",
" <td>1.0140</td>\n",
" <td>-0.0665</td>\n",
" <td>0.2514</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>15.57</td>\n",
" <td>[9.735545]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Tata</td>\n",
" <td>Sumo EX</td>\n",
" <td>Coimbatore</td>\n",
" <td>Diesel</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>0.5106</td>\n",
" <td>0.2558</td>\n",
" <td>-0.6101</td>\n",
" <td>2.2491</td>\n",
" <td>-0.5565</td>\n",
" <td>2.1244</td>\n",
" <td>-0.2485</td>\n",
" <td>5.29</td>\n",
" <td>[5.969137]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Datsun</td>\n",
" <td>#na#</td>\n",
" <td>Kolkata</td>\n",
" <td>Petrol</td>\n",
" <td>Manual</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>0.8188</td>\n",
" <td>-0.4392</td>\n",
" <td>1.0140</td>\n",
" <td>-1.3861</td>\n",
" <td>-1.1312</td>\n",
" <td>-0.3457</td>\n",
" <td>0.0605</td>\n",
" <td>2.25</td>\n",
" <td>[2.973508]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>BMW</td>\n",
" <td>X5 xDrive 30d</td>\n",
" <td>Chennai</td>\n",
" <td>Diesel</td>\n",
" <td>Automatic</td>\n",
" <td>First</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>-1.3381</td>\n",
" <td>0.5049</td>\n",
" <td>-1.4002</td>\n",
" <td>2.3115</td>\n",
" <td>2.5152</td>\n",
" <td>-0.3457</td>\n",
" <td>-0.2485</td>\n",
" <td>20.0</td>\n",
" <td>[17.299963]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "POO2TIFc1j3J",
"outputId": "7d2ad68b-0101-44ba-a372-2909b72b6e88",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 102
}
},
"source": [
"#Getting The Training And Validation Errors\n",
"\n",
"tr = learn.validate(learn.data.train_dl)\n",
"va = learn.validate(learn.data.valid_dl)\n",
"print(\"The Metrics used In Evaluating The Network:\", str(learn.metrics))\n",
"\n",
"print(\"\\nThe calculated RMSE & R-Squared For The Training Set :\", tr[1:])\n",
"print(\"\\nThe calculated RMSE & R-Squared For The Validation Set :\", va[1:])"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"The Metrics used In Evaluating The Network: [<function root_mean_squared_error at 0x7fe2cd330268>, <function r2_score at 0x7fe2cd330400>]\n",
"\n",
"The calculated RMSE & R-Squared For The Training Set : [tensor(1.6506), tensor(0.9713)]\n",
"\n",
"The calculated RMSE & R-Squared For The Validation Set : [tensor(3.0779), tensor(0.9166)]\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Tx9o36q0CLWs",
"colab_type": "text"
},
"source": [
"Summary:\n",
"\n",
"The Root Mean Squared Error is the standard deviation of the errors/residuals. It tells us the 'Goodness Of Fit' of a model. The lower the value of RMSE the better the model.\n",
"\n",
"The R-Squared metric also called the coefficient of determination is used to understand the variation in the dependent variable(y) and the independent variable(X).The closer the value of R-Squared is to one, the better the model.\n",
"\n",
"**The above output suggests that:**\n",
"\n",
"**The model/network was able to attain an RMSE of 1.4678 and an R_squared of 0.9726 while training and an RMSE of 3.1737 and an R_squared of 0.9107 while Validating on the validation set.**\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "YUKxTHXkVpPv",