Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture1 U5

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

Model Development and

Evaluation

Unit-5
Model Development and Evaluation with
Python
Model Development
• In this section, we will develop several models
that will predict the price of the car using the
variables or features. This is just an estimate
but should give us an objective idea of how
much the car should cost.
Model Development and Evaluation with
Python
Some questions we want to ask in this kernel
1. do I know if the dealer is offering fair value for my
trade-in?
2. do I know if I put a fair value on my car?

• Data Analytics, we often use Model Development to help


us predict future observations from the data we have.
• A Model will help us understand the exact relationship
between different variables and how these variables are
used to predict the result.
Model Development and Evaluation with
Python
Setup
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
from ipywidgets import interact, interactive, fixed,
interact_manual, widgets
Model Development and Evaluation with
Python
from google.colab import
drivedrive.mount('/content/drive')

Output:
Mounted at /content/drive
Model Development and Evaluation with Python

df = pd.read_csv('/content/drive/MyDrive/dataanalysis/auto_clean.csv')
df.head()

Output:
Model Development and Evaluation with
Python
1. Linear Regression
• One example of a Data Model that we will be
using is Simple Linear Regression.
• Simple Linear Regression is a method to help us
understand the relationship between two
variables:
i. The predictor/independent variable (X)
ii. The response/dependent variable (that we
want to predict)(Y)
Model Development and Evaluation with
Python
• The result of Linear Regression is a linear
function that predicts the response
(dependent) variable as a function of the
predictor (independent) variable.
Y : Response Variable
X : Predictor Variables
Model Development and Evaluation with
Python
Linear function:
• a refers to the intercept of the regression
line0, in other words: the value of Y when X is
0
• b refers to the slope of the regression line, in
other words: the value with which Y changes
when X increases by 1 unit
Model Development and Evaluation with
Python
• Lets load the modules for linear regression
from sklearn.linear_model import LinearRegression

• Create the linear regression object


lm = LinearRegression()
Lm

Output:
Model Development and Evaluation with
Python
How could Highway-mpg help us predict car price?
For this example, we want to look at how highway-mpg can help
us predict car price. Using simple linear regression, we will
create a linear function with "highway-mpg" as the predictor
variable and the "price" as the response variable.

X = df[['highway-mpg']]
Y = df['price']
Model Development and Evaluation with
Python
• Fit the linear model using highway-mpg.
lm.fit(X,Y)
Output:

• We can output a prediction


Yhat = lm.predict(X)
Yhat[0:5]
Output:
array([16236.50464347, 16236.50464347, 17058.23802179,
13771.3045085 , 20345.17153508])
Model Development and Evaluation with
Python
• What is the value of the intercept (a)?
lm.intercept_
Output:
38423.3058581574

• What is the value of the Slope (b)?


lm.coef_
Output:
array([-821.73337832])
Model Development and Evaluation with
Python
• What is the final estimated linear model we get?
• As we saw above, we should get a final linear model with the
structure:

Yhat=a+bX
• Plugging in the actual values we get:
• price = 38423.31 - 821.73 x highway-mpg
Model Development and Evaluation with
Python
Reference:

• https://www.kaggle.com/code/fazilbtopal/model-
development-and-evaluation-with-python

You might also like