Linear Regression is one of the most important and commonly used Machine Learning algorithms. It is usually the first algorithm students learn because it is simple, mathematically clear, and widely used in real-world applications.
Linear Regression is a supervised learning regression algorithm used to predict continuous numerical values such as price, salary, marks, or sales.
It works by fitting the best possible straight line through the data points.
Simple Linear Regression:
y = b0 + b1x
Multiple Linear Regression:
y = b0 + b1x1 + b2x2 + ... + bnxn
Linear Regression minimizes error using the Mean Squared Error (MSE):
MSE = (1/n) Σ (y − ŷ)²
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([[1],[2],[3],[4],[5]])
y = np.array([3,4,2,5,6])
model = LinearRegression()
model.fit(X, y)
print(model.intercept_)
print(model.coef_)
print(model.predict([[6]]))
Advantages: Simple, fast, interpretable
Limitations: Assumes linearity, sensitive to outliers
CodeMyFYP helps students learn Machine Learning, AI, Web Development & Final Year Projects with real-world guidance.
👉 Get Career Guidance on WhatsApp
👉 Trending Final Year Projects
🌐 Website: www.codemyfyp.com