Lab Assignment-3

 

Assignment-3- week 3 July

Learning Objective: Optimizing the parameters of the regression model.

1.The following dataset represents the relationship between the number of hours spent practicing a skill and the performance score obtained in an assessment.

Build a Polynomial Regression model and use GridSearchCV to determine the optimal polynomial degree (1–5).

Dataset
Hours of Practice (X) Performance Score (Y)
                    1                 3.2
                    2                 5.1
                    3                 8.8
                    4                 15.6
                    5                 25.4
                    6                 38.2
                    7                 54.1
                    8                 73.5
                    9                 96.8
                    10         123.2
                    11         154.6
                    12         190.8
Tasks
Create the dataset using NumPy.
Split the data into training and testing sets (80:20).
Build a Pipeline consisting of
PolynomialFeatures
LinearRegression
Use GridSearchCV to search for the best polynomial degree from 1 to 5.
Use 5-fold cross-validation.

Display
Best polynomial degree
Best cross-validation score
Predict the test set values.

Compute
Mean Squared Error (MSE)
R² Score
Plot
Original data
Best fitted polynomial curve

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)
15
28
315
424
536
650
767
885
9108
10130
11158
12190
13225
14265
15310

The data approximately follows a quadratic relationship with a small amount of noise.


Tasks

  1. Create the dataset using NumPy.
  2. Split the data into training and testing sets (70:30).
  3. Train Polynomial Regression models with degrees 1, 2, 3, 4, 5, and 6.
  4. For each model:
    • Calculate the training MSE.
    • Calculate the testing MSE.
  5. Display the results in a table.
  6. Plot:
    • Training Error vs Degree
    • Testing Error vs Degree
  7. 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    1011
60    25    1213
70    35    1516
80    40    1818
90    45    2020
100    50    2223
110    55    2425
120    60    2628
130    65    2830
140    70    3033
150    75    3235
160    80    3538

Tasks

  1. Create the dataset using Pandas.
  2. Split the dataset into training and testing sets (80:20).
  3. Train a Linear Regression model.
  4. Train a Ridge Regression model with alpha = 1.0.
  5. Train a Lasso Regression model with alpha = 1.0.
  6. Predict the test data.
  7. 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

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