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
| Model | How it works | Strengths | Weaknesses |
|---|---|---|---|
| Linear regression | Fits a weighted sum of features | Fast, interpretable, a strong baseline when relationships are roughly linear | Misses interactions and curves unless you engineer them; sensitive to outliers |
| Ridge, Lasso, Elastic Net | Linear regression with a penalty on large weights | Handles many correlated features; Lasso can drop useless ones | Still linear; needs feature scaling |
| Random forest regressor | Averages many deep decision trees | Captures non-linearity with little tuning, robust | Cannot predict outside the range seen in training; large models |
| XGBoost / LightGBM | Adds shallow trees one at a time, each fixing the previous errors | Usually the most accurate on tabular data, handles missing values, fast | Needs early stopping and tuning; also cannot extrapolate beyond training range |
| Neural network (MLP) | Layers of learned non-linear transformations | Useful for very large data or when combining images or text with numbers | Needs 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.
| Metric | What it measures | Units | Use it when | Caveat |
|---|---|---|---|---|
| MAE (mean absolute error) | Average size of the error | Same as target | Every unit of error costs the same; easy to explain | Does not punish occasional large misses heavily |
| RMSE (root mean squared error) | Square root of the average squared error | Same as target | Large errors are disproportionately costly | Dominated by a few outliers |
| R2 (coefficient of determination) | Share of the target's variance the model explains | Unitless, at most 1 | Comparing models on the same dataset | Can 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 value | Percent | Stakeholders think in percentages and targets are well above zero | Breaks when true values are zero or near zero; penalises over-forecasts more |
| RMSLE | RMSE on log-transformed values | Unitless | Targets span orders of magnitude and relative error matters | Hard 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
- Check the target's distribution. A strongly right-skewed target such as price or revenue often trains better on a log scale; transform it back before reporting errors.
- Look at outliers before deleting them. Some are data entry errors, others are the rare, expensive cases the model most needs to learn.
- Encode categories sensibly: one-hot encoding for linear models, native categorical handling or ordinal codes for tree ensembles.
- Scale numeric features for linear models and neural networks; tree-based models do not need it.
- Remove leaky features, such as a final invoice total when predicting the order value at checkout.
Common regression mistakes
- Expecting tree models to extrapolate. Random forests and boosted trees predict within the range of targets they have seen, so they will not forecast a record high price.
- Using MAPE on data with zeros, which produces infinite or meaningless percentages.
- Shuffling time-ordered data before splitting, which lets the model peek at the future.
- Judging the model on R2 alone without checking residuals; a pattern in the residuals means signal the model missed.
How to train a regression model online with TensorTurn
- Upload a CSV, Excel, Parquet or JSON file, or import one from a URL, Hugging Face or Kaggle.
- Review the instant column profile: missing values, min and max, skewness, kurtosis and histograms for every column, plus outlier analysis with IQR fences and the most anomalous rows ranked by modified z-score.
- Use target analysis to see which features carry predictive signal for your numeric target and which are flagged as possible leakage.
- Clean the data with the AI data editor, for example fill missing values with the median, cast formatted numbers like $1,234.56 to numbers, or remove outlier rows, approving each step.
- Describe the model in chat, for example: predict sale_price with LightGBM on a log-transformed target and report MAE, RMSE and R2. TensorTurn generates and runs the notebook on cloud GPUs or on your own connected machine.
- Ask for changes in plain English, then save the best weights and deploy a live /predict endpoint, or export to ONNX.
For complete worked examples, see the house price prediction and price prediction use-case guides.
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.