Regression (1) - 1-4
Regression (1) - 1-4
Scenario:
A real estate company wants to predict the prices of houses based on various features such as the size of
the house (in square feet), the number of bedrooms, the number of bathrooms, and the age of the house (in
years).
Objective:
To build a model that can predict the house prices given the features mentioned.Suppose the dataset
contains the following columns:
Model Training: Use the training data to fit a linear regression model. The model will have the form:
1. Model Evaluation: Evaluate the model using metrics such as Mean Squared Error (MSE), Root
Mean Squared Error (RMSE), and R2R^2R2 score on the test set to determine how well it
predicts house prices.
2. Model Prediction: Use the trained model to predict the prices of new houses based on their
features.
Example Data
Library files:
● import pandas as pd
● from sklearn.model_selection import train_test_split
● fromsklearn.linear_model import LinearRegression
● from sklearn.metrics Import mean_squared_error, r2_score
MSE & MAE
Scenario A Company wants to predict the monthly electricity bill based on the
square footage of a house. They collected the following data from five houses:
Step-by-Step Calculation
Why we square the differences in the Mean Squared Error (MSE) calculation
Practice Problem
Scenario: Predict the monthly electricity consumption (in kWh) of households based on the number of
appliances. We have the following true values and predicted values:
Tasks: