Classification and Prediction · Data Mining

Prediction

Watch lectures

Prediction

1. Classification vs Prediction

Aspect Classification Prediction (numeric / regression)
Output Discrete class label (yes/no, A/B/C) Continuous numeric value (price, temperature, demand)
Model Classifier Predictor / regressor
Evaluation Accuracy, error rate, confusion matrix MAE, MSE, RMSE, R2R^2, correlation
Example 'Will the customer default?' 'What will be the sales next quarter?'

Both are supervised learning of a mapping from attributes to a target; prediction is used where exact labels are replaced by numeric estimates.

2. Main Prediction (Regression) Techniques

(a) Linear regression — the simplest, assumes a linear relationship:

y=w0+w1xy = w_0 + w_1x

with the least-squares solution:

w1=∑i=1n(xi−xˉ)(yi−yˉ)∑i=1n(xi−xˉ)2,w0=yˉ−w1xˉw_1=\frac{\sum_{i=1}^{n}(x_i-\bar x)(y_i-\bar y)}{\sum_{i=1}^{n}(x_i-\bar x)^{2}},\qquad w_0=\bar y - w_1\bar x

(b) Multiple linear regression — several independent attributes:

y=w0+w1x1+w2x2+⋯+wkxky = w_0 + w_1x_1 + w_2x_2 + \dots + w_kx_k

Weights are found by solving the normal equations W=(XTX)−1XTYW = (X^{T}X)^{-1}X^{T}Y; it can also be solved by gradient descent (the basis of neural networks). Categorical attributes are converted with dummy variables.

(c) Non-linear / other models

Method Idea
Polynomial regression y=w0+w1x+w2x2+…y = w_0+w_1x+w_2x^2+\dots — curves are fitted by treating powers as new attributes
Logistic regression P(y=1)=11+e−(w0+∑wixi)P(y=1)=\frac{1}{1+e^{-(w_0+\sum w_ix_i)}} — classification and probability estimation
Generalised linear models (GLM) Link function + distribution (Poisson, gamma) — insurance claims, counts
Regression trees (model trees) Leaves carry a linear equation, not a class; M5 / M5' algorithms
Neural networks (MLP, RBF) Universal approximators for non-linear regression
Support vector regression (SVR) ϵ\epsilon-insensitive tube, kernels for non-linearity
k-NN regression / LWR Locally weighted average of neighbours
Time-series models (AR, MA, ARIMA, exponential smoothing, Holt-Winters) Trend, seasonality and autocorrelation in sequences
Ensembles (bagging, boosting) Combine many weak regressors (random forest regression, gradient boosting)

3. Worked Least-Squares Example

Data: (x,y)=(1,2),(2,4),(3,5),(4,8)(x,y) = (1,2), (2,4), (3,5), (4,8) → xˉ=2.5\bar x = 2.5, yˉ=4.75\bar y = 4.75.

∑(xi−xˉ)(yi−yˉ)=(−1.5)(−2.75)+(−0.5)(−0.75)+(0.5)(0.25)+(1.5)(3.25)=4.125+0.375+0.125+4.875=9.5\sum (x_i-\bar x)(y_i-\bar y)=(-1.5)(-2.75)+(-0.5)(-0.75)+(0.5)(0.25)+(1.5)(3.25)=4.125+0.375+0.125+4.875=9.5
∑(xi−xˉ)2=2.25+0.25+0.25+2.25=5.0⇒w1=9.5/5=1.9,w0=4.75−1.9(2.5)=−0.0≈0\sum (x_i-\bar x)^2 = 2.25+0.25+0.25+2.25=5.0 \Rightarrow w_1 = 9.5/5 = 1.9,\quad w_0 = 4.75-1.9(2.5)=-0.0\approx0

Model: y=1.9xy = 1.9x. Prediction at x=5x=5 → y=9.5y = 9.5. Residuals: −0.1, +0.2, −0.7, +0.4-0.1,\ +0.2,\ -0.7,\ +0.4 (small, so a good linear fit).

4. Accuracy of a Predictor

Absolute error=∣yi−y^i∣,Relative error=∣yi−y^i∣∣yi∣\text{Absolute error}=|y_i-\hat y_i|,\qquad \text{Relative error}=\frac{|y_i-\hat y_i|}{|y_i|}
MAE=1n∑i=1n∣yi−y^i∣,MSE=1n∑i=1n(yi−y^i)2,RMSE=MSE\text{MAE}=\frac{1}{n}\sum_{i=1}^n|y_i-\hat y_i|,\qquad \text{MSE}=\frac{1}{n}\sum_{i=1}^n(y_i-\hat y_i)^{2},\qquad \text{RMSE}=\sqrt{\text{MSE}}
RMSErelative=RMSEyˉ (or MAE/∣y∣ per tuple),R2=1−∑(yi−y^i)2∑(yi−yˉ)2\text{RMSE}_{\text{relative}}=\frac{\text{RMSE}}{\bar y}\ (\text{or MAE}/|y|\ \text{per tuple}),\qquad R^{2}=1-\frac{\sum(y_i-\hat y_i)^2}{\sum(y_i-\bar y)^2}

Example — actual 20, 30, 40, 50; predicted 21, 28, 42, 48:
MAE =(1+2+2+2)/4=1.75= (1+2+2+2)/4 = 1.75; MSE =(1+4+4+4)/4=3.25= (1+4+4+4)/4 = 3.25; RMSE =1.80= 1.80; mean yˉ=35\bar y = 35, so relative RMSE ≈5.1%\approx 5.1\%.

5. Handling Overfitting and Underfitting

  • Overfitting — the model fits noise (too many attributes/parameters, too deep a tree): low training error, high test error. Fix with pruning, regularisation (L1L_1 Lasso, L2L_2 Ridge), more data, cross-validation.
  • Underfitting — the model is too simple: high error on both. Fix with more/better features, a more flexible model.
J=∑(yi−y^i)2⏟error+λ∥w∥2⏟regularisation penaltyJ = \underbrace{\sum (y_i-\hat y_i)^{2}}_{\text{error}} + \underbrace{\lambda\|w\|^{2}}_{\text{regularisation penalty}}

Regularisation shrinks coefficients:

Ridge: W^=(XTX+λI)−1XTY,Lasso adds λ∑j∣wj∣ (performs selection)\text{Ridge: } \hat W = (X^{T}X+\lambda I)^{-1}X^{T}Y,\qquad \text{Lasso adds } \lambda\sum_j |w_j| \text{ (performs selection)}

6. Choosing a Model / Avoiding Overfitting

Split data into training / validation / test; use cross-validation for tuning; prefer the simplest model that fits (Occam's razor); check the bias-variance trade-off; use domain constraints.

E[error]=Bias2+Variance+Irreducible noise\mathbb{E}[\text{error}] = \text{Bias}^2 + \text{Variance} + \text{Irreducible noise}

7. Applications of Prediction

Sales and demand forecasting, financial time-series forecasting, price and risk estimation, medical dosage/prognosis, weather and energy-load prediction, click-through/response prediction, predictive maintenance, customer lifetime value.

8. Exam Points

  • Explain linear and multiple regression for prediction with the least-squares formulas — 10 marks (frequent).
  • Numerical: fit a regression line from given data and predict — 5-7 marks (very frequent).
  • Compute MAE, MSE, RMSE, relative error and R2R^2 for predicted vs actual values — 5 marks.
  • Difference between classification and prediction — 3-5 marks.
  • Discuss overfitting and regularisation — 5 marks.
Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.

← All Data Mining modules