Lab # 9
Lab # 9
Lab Manual 09
CS3151-Artificial Intelligence Lab
Table of Contents
1 Objectives ............................................................................................................................... 3
2 Task Distribution ..................................................................................................................... 3
3 Linear Regression ................................................................................................................... 3
3.1 Key Concepts ................................................................................................................... 4
3.2 Assumptions of Linear Regression .................................................................................. 4
4 Steps in Performing Linear Regression: ................................................................................. 4
4.1 Applications of Linear Regression ................................................................................... 4
5 Example .................................................................................................................................. 5
6 Code ........................................................................................................................................ 5
7 Exercise (50 Marks) ................................................................................................................ 6
8 Submission Instructions .......................................................................................................... 6
CS3151: Artificial Intelligence Lab
1 Objectives
After performing this lab, students shall be able to understand the following:
Linear Regression
Linear Regression model with scikit-learn
2 Task Distribution
Total Time 170 Minutes
3 Linear Regression
Linear regression uses the relationship between the data-points to draw a straight line through all
them. Linear regression is a statistical method used to model the relationship between a dependent
variable and one or more independent variables. The goal is to find a linear equation that best
predicts the dependent variable based on the independent variables. The simplest form is simple
linear regression, which involves a single independent variable. Multiple linear regression involves
two or more independent variables.
This line can be used to predict future values
CS3151: Artificial Intelligence Lab
Linearity: The relationship between the dependent and independent variables is linear.
Independence: The residuals (errors) are independent.
Homoscedasticity: The residuals have constant variance at every level of XXX.
Normality: The residuals of the model are normally distributed.
5 Example
Consider a simple linear regression model predicting house prices (Y) based on square footage
(X):
Linear regression is a foundational technique in statistics and machine learning, widely used for
its simplicity and interpretability.
6 Code
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
import matplotlib.pyplot as plt
y_pred = model.predict(X_test)
8 Submission Instructions
Always read the submission instructions carefully.
• Rename your Jupyter notebook to your roll number and download the notebook as
.ipynb extension.
• To download the required file, go to File->Download .ipynb
• Only submit the .ipynb file. DO NOT zip or rar your submission file.
• Submit this file on Google Classroom under the relevant assignment.
• Late submissions will not be accepted