0% found this document useful (0 votes)
4 views4 pages

Regression (1) - 1-4

The document outlines a linear regression model aimed at predicting house prices based on features such as size, number of bedrooms, bathrooms, and age. It details the steps for building the model, including data collection, preprocessing, training, evaluation, and prediction. Additionally, it discusses the importance of using squared differences in Mean Squared Error calculations and provides a practice problem related to predicting monthly electricity consumption.

Uploaded by

sfnasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Regression (1) - 1-4

The document outlines a linear regression model aimed at predicting house prices based on features such as size, number of bedrooms, bathrooms, and age. It details the steps for building the model, including data collection, preprocessing, training, evaluation, and prediction. Additionally, it discusses the importance of using squared differences in Mean Squared Error calculations and provides a practice problem related to predicting monthly electricity consumption.

Uploaded by

sfnasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Linear Regression:

Predicting House Prices

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:

Price: The price of the house (dependent variable).


Size: The size of the house in square feet.
Bedrooms: The number of bedrooms in the house.
Bathrooms: The number of bathrooms in the house.
Age: The age of the house in years.

Steps to Build a Linear Regression Model


Collect Data: Gather historical data on house sales in the area.
Preprocess Data:

● Handle missing values.


● Normalize/standardize features if necessary.
● Split the data into training and test sets.

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

Differences and Squared Differences

Sum of Absolute Differences and Squared Differences

● Sum of absolute differences:


REASON :

Why we square the differences in the Mean Squared Error (MSE) calculation

● Scenario 1: Small errors


○ Actual values: [3, 4]
○ Predicted values: [2.5, 4.5]
○ Differences: [-0.5, 0.5]
● Scenario 2: Larger errors
○ Actual values: [3, 4]
○ Predicted values: [1, 6]
○ Differences: [-2, 2]

If we use the absolute errors (like in Mean Absolute Error):

● Scenario 1: ∣−0.5∣+∣0.5∣=1| -0.5 | + | 0.5 | = 1∣−0.5∣+∣0.5∣=1


● Scenario 2: ∣−2∣+∣2∣=4| -2 | + | 2 | = 4∣−2∣+∣2∣=4

If we use squared errors (like in Mean Squared Error):

● Scenario 1: (−0.5)2+(0.5)2=0.25+0.25=0.5(-0.5)^2 + (0.5)^2 = 0.25 + 0.25 =


0.5(−0.5)2+(0.5)2=0.25+0.25=0.5
● Scenario 2: (−2)2+(2)2=4+4=8(-2)^2 + (2)^2 = 4 + 4 = 8(−2)2+(2)2=4+4=8

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:

1. Calculate the Mean Squared Error (MSE).


2. Calculate the Mean Absolute Error (MAE).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy