A Mathematical implementation of Simple_Linear_Regression using Python
Here's a simple and clean explanation you can use in your README.md file for your code:
This Python script implements Simple Linear Regression from scratch using NumPy, Pandas, and Matplotlib.
It predicts the salary of an employee based on their years of experience.
-
๐ฅ Reads salary data from a CSV file
-
๐ Calculates regression line using the least squares method
-
๐ Predicts salary for a custom input value
-
๐ Plots:
- Data points (scatter plot)
- Best-fit regression line
- Predicted point with dashed lines to x/y axes
-
๐ Displays model accuracy using Rยฒ Score
The dataset (Salary_dataset.csv) should contain two columns:
| YearsExperience | Salary |
|---|---|
| 1.2 | 39344.0 |
| 2.3 | 39892.0 |
| ... | ... |
-
Load Data Loads the dataset and splits it into independent variable
x(Years of Experience) and dependent variabley(Salary). -
Calculate Parameters
slopeis calculated using the least squares formulay_interceptis computed using mean values
-
Predict Values Uses the formula: y = mx + c
where:
m= slopec= y-intercept
-
Plot Results
- Plots original data and regression line
- Highlights a predicted salary for a given experience value with a green
Xand dashed guide lines
-
Evaluate Accuracy
- Calculates Rยฒ Score (model accuracy)
- Red line โ Regression line
- Blue dots โ Actual data points
- Green X โ Predicted point (with dashed lines to x and y axes)
Let me know if you want me to generate a complete
README.mdfile or also include setup instructions like required libraries.