Lab Assignment-2
Assignment-2- week 2 July
Learning Objective: Learn linear regression and polynomial regression
- 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 | 1 | 45 |
| 2 | 2 | 50 |
| 3 | 3 | 54 |
| 4 | 4 | 60 |
| 5 | 5 | 65 |
| 6 | 6 | 70 |
| 7 | 7 | 74 |
| 8 | 8 | 80 |
- 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
| House | Area (X₁) | Age (X₂) | Price (Y) |
|---|---|---|---|
| 1 | 1.0 | 10 | 20 |
| 2 | 1.5 | 8 | 24 |
| 3 | 2.0 | 6 | 29 |
| 4 | 2.5 | 5 | 32 |
| 5 | 3.0 | 3 | 38 |
| 6 | 3.5 | 2 | 43 |
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:
- The original data points with the fitted regression line.
- The Cost (MSE) vs. Iterations graph to visualize how Gradient Descent converges.
Dataset
| Employee | Experience (Years) (X) | Salary (₹ Thousand) (Y) |
|---|---|---|
| 1 | 1 | 30 |
| 2 | 2 | 35 |
| 3 | 3 | 40 |
| 4 | 4 | 45 |
| 5 | 5 | 50 |
| 6 | 6 | 56 |
| 7 | 7 | 61 |
| 8 | 8 | 66 |
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
Post a Comment