Table of Contents
ToggleLinear Regression is the simplest form of supervised learning — used to predict a continuous output by drawing a line through data points.
The equation of a line: Y = mX + c
– Y: Predicted value
– m: Slope (how steep the line is)
– X: Input feature
– c: Intercept (where line cuts Y-axis)
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import pandas as pd
# Load Data
data = pd.read_csv('housing.csv')
X = data[['Area']]
y = data['Price']
# Train-Test Split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# Model
model = LinearRegression()
model.fit(X_train, y_train)
# Prediction
y_pred = model.predict(X_test)
⏭️ Next: Model Evaluation – MAE, MSE, R² Explained
