INTRODUCTION
Linear Regression is one of the most popular supervised machine learning algorithms. It is used to predict numerical values by identifying relationships between independent and dependent variables.
For example, it can predict a student's marks based on the number of hours they study.
*WHAT IS LINEAR REGRESSION?
*
Linear Regression is a statistical and machine learning technique that finds the best-fitting straight line through a dataset to predict continuous numerical values.
*MATHEMATICAL FORMULA
*
y = mx + c
Where:
- y = Predicted output
- x = Input variable
- m = Slope
- c = Intercept
*HOW DOES IT WORK?
*
- Collect the required dataset.
- Identify input and output variables.
- Analyse the relationship between variables.
- Find the best-fitting line.
- Use the model to predict new values.
*PYTHON IMPLEMENTATION
*
Install the required libraries:
pip install numpy matplotlib scikit-learn *Python Code:
*
import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression # Sample dataset hours = np.array([1, 2, 3, 4, 5]).reshape(-1, 1) marks = np.array([20, 30, 40, 50, 60]) # Create and train model model = LinearRegression() model.fit(hours, marks) # Predict marks prediction = model.predict([[6]]) print("Predicted Marks:", prediction[0]) # Visualize results plt.scatter(hours, marks) plt.plot(hours, model.predict(hours)) plt.xlabel("Study Hours") plt.ylabel("Marks") plt.title("Linear Regression") plt.show() OUTPUT
Predicted Marks: 70.0
APPLICATIONS
- House price prediction.
- Sales forecasting.
- Salary estimation.
- Student performance prediction.
- Business analysis.
*ADVANTAGES
*
- Easy to understand and implement.
- Requires less computational power.
- Useful for numerical predictions.
- Helps identify relationships between variables.
LIMITATIONS
- Works best with approximately linear relationships.
- Sensitive to outliers.
- May not perform well with complex data patterns.
CONCLUSION
Linear Regression is an important machine learning algorithm used for predicting numerical values. It helps analyse relationships between variables and supports data-driven decisions in education, business, finance and many other fields.