Regression [With Code]: A Lighthouse for Data Scientists

About the Dataset

Linear Regression: Background Knowledge

Linear Regression: Evaluation Metrics

Regularization

1. Ridge Regression (L2)

2. Lasso Regression (L1)

Python Implementation

Importing the Required Libraries

Reading the Dataset

What’s the Target/ Response/ Dependent Variable?

Plotting Histogram of the Target Variable

Getting a ‘feel’ for our Data

Looking at the Correlation of our Features with Target Variable

Plotting a Heatmap to Study Correlation Among all the Variables

Check for Missing Values

Impute Missing Values

One-Hot encoding the Categorical Variable ‘Ocean_Proximity’

Our One-Hot Encoded Dataset

Separating into Features & Target Variable

Splitting into Training & Testing Data

Fitting the Linear Regression Model

Printing the y-intercept

Printing the Weight of the Coefficients

Plotting the Weight Coefficients for Easier Visualization

Evaluating the Linear Regression Model

Plotting the Histogram of Residuals

Ridge Regression

Lasso Regression

Wrap-Up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store