Learn the introduction to regression and regression models in Python. Understand regression concepts, build regression models, and see practical Python examples using scikit-learn and statsmodels.
Regression is a statistical and machine learning technique used to understand the relationship between a dependent variable (output) and one or more independent variables (inputs). The main goal of regression is to predict continuous values and analyze how changes in inputs affect the output.
In simple words, regression helps us answer questions like:
Regression models find the best-fit line or curve that represents the relationship between variables based on historical data.
Regression is widely used because it:
Some common types of regression include:
A simple linear regression model is represented as:
[ y = mx + c ]
Where:
A regression model is a machine learning / statistical model used to predict a continuous numerical value based on one or more input variables.
📌 Example
Predict house price based on:
Here:
We use regression to: ✔ Predict values ✔ Understand relationships ✔ Analyze trends
📌 Common predictions
| Study Hours | Marks |
|---|---|
| 1 | 35 |
| 2 | 45 |
| 3 | 55 |
| 4 | 65 |
| 5 | 75 |
📈 The model learns:
“As study hours increase, marks increase.”
Most basic and commonly used.
Formula:
y = mx + b
x → inputy → outputm → slopeb → intercept📌 Example:
Marks = 10 × StudyHours + 25
Uses more than one input
📌 Example:
Salary = Experience + Education + Skills
Used when data is curved, not straight.
📌 Example:
Used for Yes/No outcomes (classification).
📌 Example:
⚠ Although named “regression”, it’s used for classification.
from sklearn.linear_model import LinearRegression
# Input data (study hours)
X = [[1], [2], [3], [4], [5]]
y = [35, 45, 55, 65, 75]
model = LinearRegression()
model.fit(X, y)
# Predict marks for 6 hours
print(model.predict([[6]]))
✔ Measure height vs weight ✔ Predict electricity bill from units ✔ Predict sales from advertising cost ✔ Predict marks from attendance
✅ Regression predicts numbers ✅ Shows relationship between variables ✅ Linear regression draws a best-fit line ✅ Widely used in ML, data science, economics
| [Logistic Regression in Python / | Learn Logistic Regression with Examples](/python/docs/statistics/logistic-regression.html) |
| [Introduction to Confusion Matrix in Python / | Classification Evaluation](/python/docs/statistics/confusion-matrix.html) |