(Predicting Student Exam Scores)
Module 3: Linear Regression with Gradient Descent, Linear
Regression with Least squares, Polynomial regression using
Python.
Task 1: Implementing Linear Regression with Gradient
Descent
Step 1: Preprocessing the Data
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
import matplotlib.pyplot as plt
# Load the dataset
url = 'https://drive.google.com/uc?id=1TwOizNpaHfITQK_kWbFVBTlHAw0e1bxW'
data = pd.read_csv(url)
# Display the first few rows of the dataset
print(data.head())
# Display dataset information
print(data.info())
, # Check for missing values
print(data.isnull().sum())
# Separate features and target
X = data.drop('Exam_Scores', axis=1)
y = data['Exam_Scores']
# Identify categorical and numeric columns
categorical_features = ['Parental_Education', 'Ethnicity']
numeric_features = ['Hours_Studied', 'Previous_Exams']
# Preprocessing pipeline
numeric_transformer = Pipeline(steps=[
('imputer', SimpleImputer(strategy='mean')),
('scaler', StandardScaler())])
categorical_transformer = Pipeline(steps=[
('imputer', SimpleImputer(strategy='most_frequent')),