tensorturnBETA
Home › Machine Learning Tasks

Regression in Machine Learning: Models, Metrics and How to Train a Regression Model Online

Regression in machine learning predicts a continuous number, such as a house price, next month's demand, a delivery time or a customer's lifetime value, from input features. Linear regression is the classic baseline, and tree ensembles such as random forest, XGBoost and LightGBM are usually the most accurate choice for tabular data. Models are judged with error metrics such as MAE, RMSE, R2 and MAPE, each of which answers a different question. TensorTurn lets you train a regression model online by uploading your data and describing the model in plain English; it generates and runs the Python notebook for you.

What is regression in machine learning?

Regression is supervised learning with a numeric target. You provide historical rows where the answer is known, for example past sales with the final price, and the model learns how the features relate to that number. Once trained, it estimates the value for new rows. Unlike classification, the output is not a category but a quantity, so the question is never right or wrong, only how far off.

Regression shows up everywhere: pricing, demand planning, insurance claims, energy load, time to failure, lifetime value. If the target is a number where differences matter (200 is twice 100), it is a regression problem. If the numbers are really codes (1 means red, 2 means blue), treat it as classification instead. Predicting values along a time axis is usually framed as forecasting, which adds its own rules about ordering and seasonality.

Regression algorithms compared

ModelHow it worksStrengthsWeaknesses
Linear regressionFits a weighted sum of featuresFast, interpretable, a strong baseline when relationships are roughly linearMisses interactions and curves unless you engineer them; sensitive to outliers
Ridge, Lasso, Elastic NetLinear regression with a penalty on large weightsHandles many correlated features; Lasso can drop useless onesStill linear; needs feature scaling
Random forest regressorAverages many deep decision treesCaptures non-linearity with little tuning, robustCannot predict outside the range seen in training; large models
XGBoost / LightGBMAdds shallow trees one at a time, each fixing the previous errorsUsually the most accurate on tabular data, handles missing values, fastNeeds early stopping and tuning; also cannot extrapolate beyond training range
Neural network (MLP)Layers of learned non-linear transformationsUseful for very large data or when combining images or text with numbersNeeds scaling, more data and more tuning; rarely beats boosting on small tables

A practical order of work is: fit a linear model to see how much signal is easy to get, fit a gradient-boosted model to see how much non-linear signal exists, and only then decide whether extra complexity is worth it.

Regression metrics: MAE vs RMSE vs R2 vs MAPE

Choosing the metric is a business decision, not a statistical formality. The same model can look good on one metric and poor on another.

MetricWhat it measuresUnitsUse it whenCaveat
MAE (mean absolute error)Average size of the errorSame as targetEvery unit of error costs the same; easy to explainDoes not punish occasional large misses heavily
RMSE (root mean squared error)Square root of the average squared errorSame as targetLarge errors are disproportionately costlyDominated by a few outliers
R2 (coefficient of determination)Share of the target's variance the model explainsUnitless, at most 1Comparing models on the same datasetCan look good while errors are still too large in practice; can be negative
MAPE (mean absolute percentage error)Average error as a percentage of the true valuePercentStakeholders think in percentages and targets are well above zeroBreaks when true values are zero or near zero; penalises over-forecasts more
RMSLERMSE on log-transformed valuesUnitlessTargets span orders of magnitude and relative error mattersHard to explain to non-technical readers

Report at least one absolute metric (MAE or RMSE) next to R2. A model with R2 of 0.9 might still be off by 50,000 on a house price, and only the absolute number tells you whether that is acceptable.

Preparing data for a regression model

Common regression mistakes

How to train a regression model online with TensorTurn

For complete worked examples, see the house price prediction and price prediction use-case guides.

Start building free

Frequently asked questions

What is the best regression algorithm?

For tabular data, gradient-boosted trees such as XGBoost or LightGBM are usually the most accurate, with linear or ridge regression as a fast baseline. The best choice depends on your data size, how non-linear the relationships are, and whether you need to extrapolate.

Should I use MAE or RMSE?

Use MAE when every unit of error costs the same and you want an easy-to-explain number. Use RMSE when large errors are disproportionately harmful, since squaring the errors makes big misses count more. Reporting both is common.

What is a good R2 score?

There is no universal threshold. In physical systems an R2 above 0.9 is common, while in human behavior or finance 0.3 can be useful. Always check an absolute error metric too, because R2 alone does not tell you if the errors are small enough to act on.

Why does my regression model predict the same range of values every time?

Tree-based models cannot predict values outside the range of targets in the training data, so they flatten at the extremes. If you need extrapolation, consider a linear component, more representative training data, or modeling a ratio or difference instead of the raw value.

Do I need to scale features for regression?

Linear models with regularization and neural networks need scaled features. Random forests and gradient-boosted trees split on thresholds, so scaling makes no difference to them.