Linear Regression
Linear regression is the simplest and most fundamental machine learning algorithm. It models the relationship between a dependent variable (target) and one or more independent variables (features) by fitting a straight line.
Linear regression finds the best‑fitting line: y = w₁x₁ + w₂x₂ + ... + b.
Simple Linear Regression (One Feature)
Predict salary based on years of experience. Formula: `salary = w * experience + b`.
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([[1],[2],[3],[4]]) # experience
y = np.array([30000,35000,40000,45000]) # salary
model = LinearRegression()
model.fit(X, y)
print(f"Slope: {model.coef_[0]:.2f}") # w
print(f"Intercept: {model.intercept_:.2f}") # bMultiple Linear Regression (Multiple Features)
Predict house price using size, bedrooms, age.
X = np.array([[1500,3,10],[1800,4,5],[1200,2,15]])
y = np.array([300000,400000,250000])
model.fit(X, y)
print(model.predict([[1600,3,8]]))Assumptions (Brief)
- Linear relationship between features and target.
- Independence of errors.
- Homoscedasticity (constant variance of errors).
Two Minute Drill
- Linear regression predicts a continuous target.
- Simple: one feature; multiple: many features.
- Equation: y = w₁x₁ + ... + b.
- Use scikit‑learn
LinearRegression.
Need more clarification?
Drop us an email at career@quipoinfotech.com
