Lab Assignment-2

Assignment-2- week 2 July

Learning Objective: Learn linear regression and polynomial regression

1.A university wants to predict a student's final examination score based on the number of hours studied.
  • X: Number of hours studied
  • Y: Final examination score (out of 100)

Using the given dataset, implement Simple Linear Regression by computing the regression coefficients using the 

Predict the examination score for a student who studies 9 hours.

Plot the data points and regression line


Dataset

Student    Hours Studied (X)Exam Score (Y)
1        145
2    250
3    354
4    460
5    565
6    670
7    774
8    880

2.A real estate company wants to predict the selling price of a house based on two independent variables:
  • X₁: Area of the house (in 1000 sq. ft.)
  • X₂: Age of the house (in years)

The selling price (Y) is measured in lakhs of rupees.

Using the given dataset, implement Multiple Linear Regression by computing the regression coefficients using the Normal Equation (Matrix Form).

Predict the price when area is 4 and age is 1

Dataset

HouseArea (X₁)Age (X₂)Price (Y)
11.01020
21.5824
32.0629
42.5532
53.0338
63.5243

3.A company wants to predict an employee's monthly salary based on years of work experience.

Implement Simple Linear Regression using the Gradient Descent algorithm to determine the best-fit regression line.

plot:

  1. The original data points with the fitted regression line.
  2. The Cost (MSE) vs. Iterations graph to visualize how Gradient Descent converges.

Dataset

EmployeeExperience (Years) (X)Salary (₹ Thousand) (Y)
1130
2235
3340
4445
5550
6656
7761
8866

Use scikit-learn to do the following programs

4.Implement linear regression with one variable on the California Housing dataset to predict housing prices based on a single feature (e.g., the average number of rooms per dwelling).

Tasks:

● Load and preprocess the datase.

● Implement linear regression using both gradient descent and the normal equation.

● Evaluate the model performance using metrics such as Mean Squared Error

(MSE) and R-squared.

● Visualize the fitted line along with the data points.


5.Implement polynomial regression on the Auto MPG dataset to predict miles per gallon (MPG) based on engine displacement. Compare polynomial regression results with linear regression.

Tasks:

● Load and preprocess the dataset.

● Implement polynomial regression of varying degrees.

● Compare the polynomial regression models with linear regression using metrics such as MSE and R-squared.

● Visualize the polynomial fit.

Comments

Popular posts from this blog

Machine Learning Lab PCCSL508 Semester 5 KTU CS 2024 Scheme manual - Dr Binu V P

Explore California Housing Dataset

Lab Assignment-1