22IZ023 Nikhil - Exercise 6_ Linear Regression
22IZ023 Nikhil - Exercise 6_ Linear Regression
Aim
To implement a linear regression model for predicting glucose levels based on age
using Python.
Logic Description
Linear regression is a statistical method used to model the relationship between a
dependent variable (Glucose) and an independent variable (Age). The model learns
a linear equation to make predictions.
Algorithm
Package/Tools Description
# Step 5: Split the dataset into training and testing sets (80% train,
20% test)
X = df[['Age']] # Feature
y = df['Glucose'] # Target variable
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2, random_state=42)
Output:-
Test Cases
Inferences
● The model predicts glucose levels based on age with a linear relationship.
● Model performance depends on data distribution and quality.
● A lower MSE and a higher R² indicate better model accuracy.
Result
Linear regression was successfully implemented for predicting glucose levels,
demonstrating an understanding of regression analysis using Python.