Machine Learning β€” Classification vs Regression

Objectives: Machine Learning β€” Classification vs Regression

Machine Learning β€” Classification vs Regression (EN / SW)

Machine Learning β€” Classification vs Regression

Overview (English)

Supervised machine learning problems where the goal is to predict a numeric value are called regression. Problems where the goal is to predict a category / label are called classification.

This document explains core differences, formulas, symbols, real-world examples, diagrams (SVG + JS), and practical tips.

Key differences β€” quick table
AspectClassificationRegression
Target typeDiscrete labels (e.g., {spam, not-spam})Continuous numerical values (e.g., price)
Loss examplesCross-entropy, Hinge lossMean Squared Error (MSE), MAE
EvaluationAccuracy, Precision, Recall, F1, ROC-AUCRMSE, MAE, RΒ² (coefficient of determination)
Output activationSoftmax / SigmoidLinear
Typical modelsLogistic regression, SVM, Decision Trees, Random Forest, Neural Nets (with softmax)Linear regression, Ridge/Lasso, Decision Trees, Random Forest, Neural Nets (linear output)
Mathematical definitions & formulas

Below we show simple core formulas with clear explanation of every symbol.

Regression β€” Simple linear regression model
y = \beta_0 + \beta_1 x

y = predicted numeric value (target).
x = input feature (one-dimensional example).
\beta_0 = intercept (bias), \beta_1 = slope (weight for x).

Loss β€” Mean Squared Error (MSE)
MSE = \frac{1}{n} \sum_{i=1}^n (y_i - \hat{y}_i)^2

Symbols: n = number of samples, y_i = true value, \hat{y}_i = model prediction.

Classification β€” Logistic regression (binary)
P(y=1|x) = \sigma(z) = \frac{1}{1 + e^{-z}} , \quad z = w^T x + b

P(y=1|x) = probability the label is 1 given x.
\sigma(\cdot) = sigmoid activation.
z = linear score, with w (weights vector), b (bias).

Loss β€” Binary cross-entropy (log loss)
L = -\frac{1}{n} \sum_{i=1}^n \left[ y_i \log(\hat{p}_i) + (1-y_i) \log(1-\hat{p}_i) \right]

Symbols: \hat{p}_i = predicted probability P(y=1|x_i).

Real-world examples
  • Classification: Email spam detection (spam vs not-spam), Medical diagnosis (disease present / absent), Image recognition (cat/dog).
  • Regression: House price prediction (USD), Predicting temperature tomorrow (Β°C), Estimating age from continuous features.

Example: For hospital triage β€” classification to decide 'urgent' vs 'non-urgent' and regression to estimate 'expected wait time in minutes'.

Visual demos (interactive)

Below are two SVG diagrams. Use the toggle to see classification vs regression.

Evaluation metrics β€” formulas and meanings
Regression
RMSE = \sqrt{\frac{1}{n}\sum_{i=1}^n (y_i - \hat{y}_i)^2}

Root Mean Squared Error β€” lower is better; same units as y.

Classification (binary) β€” Confusion matrix terms
Accuracy = \frac{TP + TN}{TP + TN + FP + FN}

TP = true positives, TN = true negatives, FP = false positives, FN = false negatives.

Precision / Recall / F1
Precision = \frac{TP}{TP + FP} \quad Recall = \frac{TP}{TP + FN} \quad F1 = 2 \cdot \frac{Precision \cdot Recall}{Precision + Recall}

Use precision/recall when class imbalance matters (e.g., disease detection where positive class is rare).

Practical tips for choosing models
  • If target is numeric & continuous β†’ regression family. Start with linear regression, then try tree-based or neural nets if non-linear.
  • If target is categorical β†’ classification family. For many categories, use softmax output (multiclass). For imbalance, consider resampling or class weights.
  • Feature scaling: For models like SVM or logistic regression, standardize features. For tree-based models, scaling is less critical.
  • Regularization: Ridge/Lasso for regression, L2/L1 for classification to prevent overfitting.
Practical code examples (Python / scikit-learn)

These snippets show how the task setup differs in code.

Regression example
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Classification example (binary)
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()
clf.fit(X_train, y_train)
probs = clf.predict_proba(X_test)[:,1]
y_pred = clf.predict(X_test)

Note: predict_proba returns probabilities; choose threshold (default 0.5) or tune via ROC.

Symbols & glossary
  • x β€” input feature vector (single feature x or vector \(\mathbf{x}\)).
  • y β€” true target; numeric for regression, discrete label for classification.
  • \hat{y} β€” model prediction (numeric or label).
  • \hat{p} β€” predicted probability for a positive class.
  • \beta, w β€” model parameters (weights).
  • b, \beta_0 β€” bias / intercept.
  • n β€” sample size.
Created: Interactive single-page notes with diagrams, formulas and code snippets.
Machine Learning β€” Classification vs Regression (EN / SW)

Machine Learning β€” Classification vs Regression

Overview SUMMARY (English)

Supervised machine learning predicts either numeric values (regression) or categories/labels (classification).

Key differences β€” quick table
AspectClassificationRegression
Target typeDiscrete labels (e.g., {spam, not-spam})Continuous numeric values (e.g., price)
Loss examplesCross-entropy, Hinge lossMean Squared Error (MSE), MAE
EvaluationAccuracy, Precision, Recall, F1, ROC-AUCRMSE, MAE, RΒ²
Output activationSoftmax / SigmoidLinear
Typical modelsLogistic regression, SVM, Decision Trees, Random ForestLinear regression, Ridge/Lasso, Decision Trees, Random Forest
Mathematical definitions & formulas
Regression β€” Simple linear regression model
y = β0 + β1 x

y = predicted numeric value
x = input feature
β0 = intercept (bias), β1 = slope (weight)

Loss β€” Mean Squared Error (MSE)
MSE = (1/n) ∑i=1n (yi - yΜ‚i)Β²

n = number of samples, yi = true value, yΜ‚i = predicted value

Classification β€” Logistic regression (binary)
P(y=1|x) = σ(z) = 1 / (1 + e-z) , z = wTx + b

P(y=1|x) = probability label is 1, σ = sigmoid, z = linear score (weights w, bias b)

Loss β€” Binary cross-entropy
L = -(1/n) ∑i=1n [yi log(pΜ‚i) + (1 - yi) log(1 - pΜ‚i)]
Real-world examples
  • Classification: Email spam detection, Medical diagnosis (disease present/absent), Image recognition (cat/dog)
  • Regression: House price prediction, Temperature prediction, Age estimation

Reference Book: N/A

Author name: SIR H.A.Mwala Work email: biasharaboraofficials@gmail.com
#MWALA_LEARN Powered by MwalaJS #https://mwalajs.biasharabora.com
#https://educenter.biasharabora.com

:: 1::

β¬… ➑