Lab Assignment-3
Assignment-3- week 3 July
Learning Objective: Optimizing the parameters of the regression model.
2.Implement Polynomial regression on Auto MPG data set using Grid Serach and Cross Validation to select the optimal polinomial for regression.
3.The following dataset represents the relationship between the study hours of students and their examination scores.
Fit Polynomial Regression models of different degrees (1 to 6). Compare their training and testing errors to identify underfitting, overfitting, and the optimal model complexity.
Dataset
| Hours Studied (X) | Exam Score (Y) |
|---|---|
| 1 | 5 |
| 2 | 8 |
| 3 | 15 |
| 4 | 24 |
| 5 | 36 |
| 6 | 50 |
| 7 | 67 |
| 8 | 85 |
| 9 | 108 |
| 10 | 130 |
| 11 | 158 |
| 12 | 190 |
| 13 | 225 |
| 14 | 265 |
| 15 | 310 |
The data approximately follows a quadratic relationship with a small amount of noise.
Tasks
- Create the dataset using NumPy.
- Split the data into training and testing sets (70:30).
- Train Polynomial Regression models with degrees 1, 2, 3, 4, 5, and 6.
-
For each model:
- Calculate the training MSE.
- Calculate the testing MSE.
- Display the results in a table.
-
Plot:
- Training Error vs Degree
- Testing Error vs Degree
-
Identify:
- Underfitting model
- Best model
- Overfitting model
4.Use California Housing dataset from sklearn and do the following ( understand bias variance trade off)
- Load dataset
- Select one feature (e.g., RM: average rooms)
- Split into train and validation sets
- Apply polynomial regression for different degrees
- Compute training and validation MSE
- Plot error curves
- Analyze results
5.The following dataset contains the advertising expenditure on TV, Radio, and Newspaper and the corresponding product sales.
Develop Linear Regression, Ridge Regression, and Lasso Regression models to predict sales. Compare the models based on regression coefficients, Mean Squared Error (MSE), and R² Score.
Dataset
| TV | Radio | Newspaper | Sales |
|---|---|---|---|
| 50 | 30 | 10 | 11 |
| 60 | 25 | 12 | 13 |
| 70 | 35 | 15 | 16 |
| 80 | 40 | 18 | 18 |
| 90 | 45 | 20 | 20 |
| 100 | 50 | 22 | 23 |
| 110 | 55 | 24 | 25 |
| 120 | 60 | 26 | 28 |
| 130 | 65 | 28 | 30 |
| 140 | 70 | 30 | 33 |
| 150 | 75 | 32 | 35 |
| 160 | 80 | 35 | 38 |
Tasks
- Create the dataset using Pandas.
- Split the dataset into training and testing sets (80:20).
- Train a Linear Regression model.
- Train a Ridge Regression model with alpha = 1.0.
- Train a Lasso Regression model with alpha = 1.0.
- Predict the test data.
-
Compare the models using:
- Regression coefficients
- Mean Squared Error
- R² Score
6.Implement Ridge and Lasso regression on the Diabetes dataset. Compare the performance of these regularized models with standard linear regression.
Tasks:
● Load and preprocess the dataset.
● Implement Ridge and Lasso regression.
● Tune hyperparameters using cross-validation.
● Compare performance metrics (MSE, R-squared) with standard linear regression.
Comments
Post a Comment