0% found this document useful (0 votes)
2 views11 pages

Lab-2 ML Regression Algorithm

Regression is a supervised learning technique for predicting continuous numerical values using a training set of input and target variables. The document explains the application of Linear Regression to predict rent based on income, detailing the steps to import libraries, load data, train the model, and output results such as slope, intercept, and R² score. It also provides a practical example with a dataset and demonstrates how to predict rent for a given income.

Uploaded by

semira Alewi
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)
2 views11 pages

Lab-2 ML Regression Algorithm

Regression is a supervised learning technique for predicting continuous numerical values using a training set of input and target variables. The document explains the application of Linear Regression to predict rent based on income, detailing the steps to import libraries, load data, train the model, and output results such as slope, intercept, and R² score. It also provides a practical example with a dataset and demonstrates how to predict rent for a given income.

Uploaded by

semira Alewi
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

What is Regression in Machine Learning?

Lab-2
Introduction

• Regression is a supervised learning technique used


to predict a continuous numerical value.
• The value of the dependent variable are real.
Terminology
• Training set: the data used to train the model
• x: input variable (feature) Training set
• y : the target variable or the output variable
• m : the number of training example
Learning Algorithm

f
The line of best fit
• Let’s apply a Linear Regression model step by step to your Income →
Rent dataset.
Income rent

23000 9500

14000 5000

24000 10000

52500 18000

43750 16000

18000 6000

15000 5000

16000 6000

41500 18000

45000 17500
Graph income versus Data
The line of best fit
• Y=mx+c, where
Linear Regression
• Predict Rent (y) based on Income (X) using Linear Regression.
• Step 1: Import Required Libraries
import numpy as np
from sklearn.linear_model import LinearRegression
Step-2: Load the data
# Data
x = [Link]([23000,14000,24000,52500,43750,
18000,15000,16000,41500,45000]).reshape(-1,1)
y = [Link]([9500,5000,10000,18000,16000,
6000,5000,6000,18000,17500])
# Model
model = LinearRegression()
[Link](x, y)
Training dataset result
print("Slope (m):", model.coef_[0])
print("Intercept (b):", model.intercept_)
print("R² Score:", [Link](X, y))
Learned Linear Regression Equation
• From the trained model:
• Slope (m) ≈ 0.378
• Intercept (b) ≈ 47.16
Final model:
Predict rent for income = 30,000
predicted_rent = [Link]([[30000]])
print(predicted_rent)
import numpy as np
from sklearn.linear_model import LinearRegression
# Data
x = [Link]([5, 15, 25, 35, 45, 55]).reshape(-1, 1)
y = [Link]([5, 20, 14, 32, 22, 38])

# Create model
model = LinearRegression()

# Train model
[Link](x, y)

# Output results
print("Slope (m):", model.coef_[0])
print("Intercept (c):", model.intercept_)
print("Score (R²):", [Link](x, y))

You might also like