Multiple Linear Regression
    1. Multiple Linear Regression algorithm that models the relationship between a dependent variable and more than one independent variables.

Equation of Multiple Linear Regression
$$ y = a_0 + a_1x_1 + a_2x_2 + a_3x_3 + ... + a_nx_n + ε $$
    • = dependent variable (target variable).
    • = the intercept (on the y-axis) of a regression line.
    • = the coefficients of a regression line.
    • = independent variables (predictor variables).
    • = the model error.

Problem statement: Build a machine learning model that can predict home prices based on area, bedrooms, and age.
    1. Predict the price of a home with an area of 2900 sqr ft, 3 bedrooms, and 45 years old.
    2. Predict the price of a home with an area of 3000 sqr ft, 4 bedrooms, and 20 years old.
    3. Predict the price of a home with an area of 3500 sqr ft, 5 bedrooms, and 35 years old.



import pandas as pd
from sklearn.linear_model import LinearRegression

df = pd.read_csv("homeprices_multivariate.csv")

x = df[["area", "bedrooms", "age"]].values
y = df["price"]

linear_regressor_model = LinearRegression()
linear_regressor_model.fit(x, y)

print(linear_regressor_model.predict([[2900, 3, 45]]))
print(linear_regressor_model.predict([[3000, 4, 20]]))
print(linear_regressor_model.predict([[3500, 5, 35]]))

[337429.55088815]
[525277.25198079]
[475479.85615775]

# Cross verify using Multiple Linear Regression formula.

def predict_using_formula(x1, x2, x3):
    a0 = linear_regressor_model.intercept_
    coefficients_arr = linear_regressor_model.coef_
    a1 = coefficients_arr[0]
    a2 = coefficients_arr[1]
    a3 = coefficients_arr[2]
    y = a0 + a1 * x1 + a2 * x2 + a3 * x3
    print(y)

predict_using_formula(2900, 3, 45)
predict_using_formula(3000, 4, 20)
predict_using_formula(3500, 5, 35)

337429.5508881467
525277.2519807946
475479.8561577523