What is Regression?
Regression is a supervised learning task where the target is a continuous numerical value. Instead of predicting a class such as "spam" or "not spam", a regression model predicts a quantity.
Examples:
- House price in pounds.
- Temperature tomorrow.
- Received signal strength.
- Localization error in meters.
- Battery lifetime in hours.
The central question is: "Given these input features, what number should the model predict?"
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Regression vs. Classification
| Question | Task |
|---|---|
| Is this email spam? | Classification |
| What is the price of this house? | Regression |
| Which modulation type is this? | Classification |
| What is the expected channel gain? | Regression |
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
1. Linear Regression
Linear regression is the simplest and most interpretable regression model. It assumes the output can be approximated by a weighted sum of the input features.
Least squares: which line has the smallest total square area?
1. Formula and symbols
- : log₁₀(distance / 10 m): 0 at 10 m, 1 at 100 m
- : Measured received power in dBm
- : Intercept: predicted power at 10 m
- : Slope in dB per decade of distance
- : Sum of squared errors: the total area of the residual squares
- : Means of the inputs and targets
- : Least-squares solution: the line with the smallest SSE
A slope of β₁ dB per decade corresponds to a path-loss exponent of −β₁/10.
2. Work with the current inputs
3. Result
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Intuition
For one feature:
- is the predicted output
- : input feature.
- : learned slope.
- : intercept.
For many features:
- : input feature
j. - : learned weight for feature
j. - : number of features.
- remains the intercept.
Training finds weights that minimize the difference between predicted and true values, often using mean squared error.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Strengths
- Very fast.
- Easy to interpret.
- Good baseline.
- Can extrapolate outside the training range.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Weaknesses
- Assumes a mostly linear relationship.
- Sensitive to outliers.
- Cannot naturally model complex feature interactions.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Best Use Cases
- Quick baselines.
- Scientific modeling where interpretability matters.
- Problems with approximately linear relationships.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
2. Ridge and Lasso Regression
Ridge and Lasso are regularized versions of linear regression. They add a penalty to discourage overly large weights.
Ridge shrinks, lasso selects: follow the coefficient paths
1. Formula and symbols
- : Matrix of 5 standardised features for n = 40 examples
- : Centred targets
- : Coefficient of feature j
- : Regularisation strength
- : Sum of squared coefficients (ridge penalty)
- : Sum of absolute coefficients (lasso penalty)
- : Correlation of feature j with the residual that excludes feature j
- : Soft-threshold: anything smaller than λ becomes exactly zero
The data were generated from β = (3, −2, 0, 1.5, 0) with correlated features 1, 3 and 5, so features 3 and 5 are decoys.
2. Work with the current inputs
3. Result
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Ridge Regression
Ridge uses an L2 penalty. It shrinks weights smoothly and is useful when many features are correlated.
Equation-style view:
- : measured target for sample
i. - : model prediction for sample
i. - adds squared errors across samples.
- measures fit error
- penalizes large feature weights.
- controls penalty strength; the intercept is normally excluded from the penalty.
In simple words, Ridge fits the data while keeping the weights from becoming unnecessarily large. This often makes the model more stable on new data.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Lasso Regression
Lasso uses an L1 penalty. It can push some weights exactly to zero, which makes it useful for feature selection.
- measures fit error
- penalizes absolute feature weights.
- controls penalty strength; the intercept is normally excluded.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Why Regularization Matters
Without regularization, a model may fit noise in the training data. Regularization constrains the fit and can improve generalization; select its strength using validation.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
3. K-Nearest Neighbors Regressor
KNN regression predicts a number by averaging the target values of nearby training examples.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Intuition
If a new house is similar to five nearby houses in the dataset, KNN predicts the average price of those five houses.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Strengths
- Simple and non-parametric.
- Can model non-linear relationships.
- No explicit training phase.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Weaknesses
- Slow prediction for large datasets.
- Sensitive to feature scaling.
- Performs poorly when irrelevant features dominate distance.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Best Use Cases
- Small datasets.
- Local interpolation problems.
- Situations where similar inputs should have similar outputs.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
4. Polynomial Regression
Polynomial regression extends linear regression by adding powers of features, such as x^2, x^3, and interactions.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Intuition
A straight line cannot fit a curved trend. Polynomial features allow a linear model to fit curves.
- : original input feature.
- : squared input feature.
- : cubed input feature.
- : learned coefficient of the first feature.
- : learned coefficient of the second feature.
- : learned coefficient of the third feature.
- : intercept.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Strengths
- Captures simple curves.
- Still relatively interpretable.
- Easy to implement.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Weaknesses
- High-degree polynomials can overfit badly.
- Extrapolation can become unrealistic.
- Feature scaling becomes important.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
5. Support Vector Regression
Support Vector Regression (SVR) is related to SVM classification. Instead of separating classes, it tries to fit a function while ignoring small errors inside a margin.
Support vector regression: a tube that ignores small misses
1. Formula and symbols
- : Slope and intercept of the fitted line
- : Half-width of the tube: misses smaller than ε cost nothing
- : Cost per unit of miss beyond the tube
- : ε-insensitive loss: grows linearly, not quadratically
Targets are standardised before fitting (so w² and the loss have comparable scales); the line is drawn back in dBm.
2. Work with the current inputs
3. Result
References for this section3
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Intuition
SVR draws a tube around the prediction function. Errors inside the tube are acceptable. The model focuses mainly on points outside the tube.
References for this section3
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Strengths
- Robust to small noise.
- Kernel functions allow non-linear regression.
- Useful for medium-sized datasets.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Weaknesses
- Can be slow for large datasets.
- Requires tuning kernel, margin, and regularization parameters.
- Less interpretable than linear regression.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
6. Decision Tree Regressor
A decision tree regressor splits the feature space into regions and predicts the average target value in each region.
A regression tree predicts with flat steps
1. Formula and symbols
- : Candidate threshold on x
- : Mean target left and right of the split
- : Training points in a leaf (at least 2 here)
- : Tree t, grown on its own bootstrap sample
- : Number of trees in the forest
30 training and 60 validation points from the dashed curve plus Gaussian noise (σ = 0.18).
2. Work with the current inputs
3. Result
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
Intuition
For house prices, a tree may first split by location, then by area, then by number of rooms. Each final leaf stores an average price.
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
Strengths
- Handles non-linear relationships.
- Easy to visualize.
- Minimal preprocessing.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Weaknesses
- Can overfit if too deep.
- Predictions are piecewise constant.
- Single trees are unstable.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
7. Random Forest Regressor
Random forest regression averages predictions from many decision trees.
A random forest averages many step functions
1. Formula and symbols
- : Candidate threshold on x
- : Mean target left and right of the split
- : Training points in a leaf (at least 2 here)
- : Tree t, grown on its own bootstrap sample
- : Number of trees in the forest
30 training and 60 validation points from the dashed curve plus Gaussian noise (σ = 0.18).
2. Work with the current inputs
3. Result
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Intuition
Each tree makes a different estimate. Averaging many trees reduces variance and gives a more stable prediction.
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
Strengths
- Strong tabular-data baseline.
- Handles feature interactions.
- Less overfitting than one decision tree.
- Works with minimal preprocessing.
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
Weaknesses
- Less interpretable than one tree.
- Cannot extrapolate beyond the training target range.
- Larger memory footprint.
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
8. Gradient Boosting and XGBoost Regressor
Gradient boosting builds trees sequentially. Each new tree learns to correct the residual errors of the current model.
Gradient boosting: each new tree fixes the remaining errors
1. Formula and symbols
- : Model after m boosting stages
- : Mean training target: the starting guess
- : Residual: what the model still gets wrong at stage m
- : Shallow tree that predicts those residuals
- : Learning rate (shrinkage): how much of each correction is added
For squared loss the residual is exactly the negative gradient, which is why this is called gradient boosting.
2. Work with the current inputs
3. Result
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
Intuition
If the model underpredicts one group of samples, the next tree focuses on reducing that underprediction. Over many rounds, the model becomes a strong predictor.
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
Strengths
- Often excellent on structured data.
- Captures non-linear relationships.
- Works well with mixed feature types.
- XGBoost adds regularization and scalable training.
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
Weaknesses
- Needs careful tuning.
- Can overfit if trees are too deep or learning rate is too large.
- Training is more sequential than random forest.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Regression Metrics
MAE, RMSE and R²: how one bad point moves each metric
1. Formula and symbols
- : Measured value of example i
- : Prediction for example i
- : Mean of the measured values
- : Number of examples (12)
- : Fraction of the variance explained by the model (1 is perfect, 0 is no better than the mean)
MAE and RMSE share the target’s unit (dB); MSE is in dB². The least-squares line is refitted after every change.
2. Work with the current inputs
3. Result
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Mean Absolute Error
Mean Absolute Error (MAE) is the average absolute difference between prediction and true value. It is easy to interpret because it uses the same unit as the target.
- is sample count
- is sample
i's prediction error; absolute value prevents opposite errors cancelling.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Mean Squared Error
Mean Squared Error (MSE) squares the errors before averaging. Large errors are punished more strongly.
- is sample count
- is measured and
ŷᵢpredicted; squaring emphasizes larger errors.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Root Mean Squared Error
Root Mean Squared Error (RMSE) is the square root of MSE. It is also in the same unit as the target.
- is sample count
- is each error; the square root returns the metric to the target's unit.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
R-squared
R-squared measures how much variance in the target is explained by the model. It is useful, but it should not be the only metric.
- : measured target for sample
i. - : prediction for sample
i. - : mean measured target over the evaluation set.
- The numerator is model squared error; the denominator is squared error from always predicting the mean.
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Practical Checklist
- Plot predicted values vs. true values.
- Check residuals for patterns.
- Scale features for KNN, SVR, linear models, and neural networks.
- Use cross-validation when data is limited.
- Compare against a simple baseline, such as predicting the mean.
- Watch out for outliers, data leakage, and target leakage.
Which fitted shape follows this numeric target?
1. Formula and symbols
- : degree
- : polynomial design matrix
- : learned coefficients
- : training targets
- : penalty
- : excludes the intercept from that penalty
- : Number of examples in the set being scored
MSE is computed separately on training and validation sets of size N.
2. Work with the current inputs
3. Result
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Python: Load Common Regressors
Regressors follow the same scikit-learn pattern as classifiers:
fit(X_train, y_train)learns the mapping.predict(X_test)returns continuous values.- Metrics such as MAE, RMSE, and R-squared evaluate the predictions.
from sklearn.linear_model import LinearRegression, Ridge, Lasso
from sklearn.neighbors import KNeighborsRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.svm import SVR
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
regressors = {
"linear": LinearRegression(),
"ridge": Ridge(alpha=1.0),
"lasso": Lasso(alpha=0.01),
"knn": KNeighborsRegressor(n_neighbors=5),
"decision_tree": DecisionTreeRegressor(max_depth=6, random_state=42),
"svr": SVR(kernel="rbf"),
"random_forest": RandomForestRegressor(n_estimators=200, random_state=42),
"gradient_boosting": GradientBoostingRegressor(random_state=42),
}
References for this section3
- Scikit-learn documentation, "RandomForestRegressor".
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Python: Compare Regressors on One Dataset
Select the family on validation data, refit that choice on development data, then inspect the final test score once. This small example uses a single split; use fold-local pipelines for cross-validation.
from sklearn.base import clone
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_absolute_error, r2_score
X, y = load_diabetes(return_X_y=True)
X_dev, X_test, y_dev, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
X_train, X_validation, y_train, y_validation = train_test_split(
X_dev, y_dev, test_size=0.25, random_state=43
)
scores = {}
for name, reg in regressors.items():
candidate = make_pipeline(StandardScaler(), clone(reg))
candidate.fit(X_train, y_train)
pred = candidate.predict(X_validation)
scores[name] = mean_absolute_error(y_validation, pred)
print(name, "validation MAE=", round(scores[name], 3))
best_name = min(scores, key=scores.get)
model = make_pipeline(StandardScaler(), clone(regressors[best_name]))
model.fit(X_dev, y_dev)
pred = model.predict(X_test)
print("Selected:", best_name)
print("Final test MAE:", mean_absolute_error(y_test, pred))
print("Final test R2:", r2_score(y_test, pred))
References for this section3
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
Python: Save and Load a Regressor
import joblib
final_regressor = RandomForestRegressor(
n_estimators=300,
max_depth=None,
random_state=42,
n_jobs=-1
)
final_regressor.fit(X_train, y_train)
joblib.dump(final_regressor, "regressor.joblib")
loaded_regressor = joblib.load("regressor.joblib")
print(loaded_regressor.predict(X_test[:5]))
References for this section3
- Scikit-learn documentation, "RandomForestRegressor".
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
Takeaway
- Regression output: a number, such as distance or received power.
- Linear model: fast and interpretable.
- Tree ensemble: often strong on tabular features; kernel/neural model: can learn more complex nonlinear patterns.
- Choose by: data shape, interpretability, error cost, and deployment budget.
Continue with Ridge and Kernel Ridge Regression to build on this note.
References for this section3
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- Scikit-learn documentation, "RandomForestRegressor".
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
Check your understanding
0 of 4 answered
Absolute prediction errors are 1 and 3 metres. What is MAE?
For those same errors, what is MSE?
Nearest-neighbour target values are 2, 4 and 9. What is the uniform KNN prediction?
Is cubic regression linear in its fitted coefficients?
Complete references and further reading
- T. Hastie, R. Tibshirani, and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009.
- J. H. Friedman, "Greedy Function Approximation: A Gradient Boosting Machine", The Annals of Statistics, vol. 29, no. 5, pp. 1189-1232, 2001.
- T. Chen and C. Guestrin, "XGBoost: A Scalable Tree Boosting System", Proceedings of ACM SIGKDD, San Francisco, CA, USA, 2016, pp. 785-794.
- Tpoint Tech/Javatpoint, "Linear Regression in Machine Learning".
- Scikit-learn documentation, "RandomForestRegressor".