Multivariate Linear Regression Demo

Source: 🤖Homemade Machine Learning repository

☝Before moving on with this demo you might want to take a look at:

Linear regression is a linear model, e.g. a model that assumes a linear relationship between the input variables (x) and the single output variable (y). More specifically, that output variable (y) can be calculated from a linear combination of the input variables (x).

Multivariate Linear Regression is a linear regression that has more than one input parameter and one output label.

Demo Project: In this demo we will build a model that will predict Happiness.Score for the countries based on Economy.GDP.per.Capita and Freedom parameters.

In [1]:
# To make debugging of linear_regression module easier we enable imported modules autoreloading feature.
# By doing this you may change the code of linear_regression library and all these changes will be available here.
%load_ext autoreload
%autoreload 2

# Add project root folder to module loading paths.
import sys

Import Dependencies

  • pandas - library that we will use for loading and displaying the data in a table
  • numpy - library that we will use for linear algebra operations
  • matplotlib - library that we will use for plotting the data
  • plotly - library that we will use for plotting interactive 3D scatters
  • linear_regression - custom implementation of linear regression
In [2]:
# Import 3rd party dependencies.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly
import plotly.graph_objs as go

# Configure Plotly to be rendered inline in the notebook.

# Import custom linear regression implementation.
from homemade.linear_regression import LinearRegression