Simple Linear Regression using Sample Data ( Single variable , Toy Example)
Experiment
Simple Linear Regression using Sample Data
Aim
To implement Simple Linear Regression on sample data and manually compute:
-
Regression coefficients
-
Mean Squared Error (MSE)
-
R-squared (R²)
Objectives
-
Build a regression model from scratch
-
Compute slope and intercept manually
-
Evaluate model using MSE and R² (without sklearn)
-
Visualize regression line
๐ ️ Tools Required
-
Python
-
NumPy
-
Matplotlib
๐ Theory
๐น Linear Regression Model
๐น Regression Coefficients
๐น Mean Squared Error (MSE)
-
Measures average squared error
-
Lower value → better model
๐น R-squared (R² Score)
Where:
-
R² = 1 → Perfect fit
-
R² = 0 → No explanatory power
๐ Procedure
-
Define dataset
-
Compute mean values
-
Calculate regression coefficients
-
Predict values
-
Compute MSE manually
-
Compute R² manually
-
Plot results
๐ป Program
Output
-
Slope and intercept values
-
Mean Squared Error (MSE)
-
R² score
-
Graph showing regression line
Result
The regression model was successfully implemented.
Model performance was evaluated using manually computed:
-
MSE
-
R² score
MSE gives error magnitude
-
R² gives goodness of fit
-
Both metrics together provide better evaluation

Comments
Post a Comment