Regression Lab
Fit regression models, inspect residuals, and learn why a better in-sample fit does not always mean a better prediction. Your CSV stays in your browser.
Dataset & model
Start with a synthetic dataset or upload your own two-column numeric CSV (header optional).
Format: x,y with one observation per row. Maximum 2,000 rows. Comma-separated, no quoted commas.
Uses ordinary least squares on scaled X values. Train/test split is deterministic and shuffled. For educational purposes, not a production forecasting system.
Model performance
Observed data & fitted curve
Training points Test points Fitted model
Model Selection & Overfitting Analysis
Compare polynomial degrees using 5-fold cross-validation on training data only. The held-out test set is never used to choose the recommended degree.
| Degree | Train RMSE | CV RMSE | CV SD | Gap |
|---|
Recommendation uses the lowest mean validation RMSE. The blue line shows fit on the full training set; orange values average held-out fold errors. The difference is a diagnostic, not proof of overfitting. CV SD describes variation between folds, not a confidence interval.
Residual diagnostics
Residual = observed Y − predicted Y. Ideally, residuals have no systematic pattern. A curved residual pattern may indicate model misspecification.
Model predictions
| Set | X | Actual Y | Predicted Y | Residual |
|---|---|---|---|---|
| Fit a model to see predictions. | ||||
Learn the concepts
What does ordinary least squares minimize?
It selects coefficients that minimize the sum of squared differences between observed and predicted values. Squaring makes large errors more influential.
What do R², MAE and RMSE mean?
R² compares squared prediction errors with predicting the mean; it can be negative on held-out data. MAE is average absolute error. RMSE is the square root of average squared error and penalizes larger mistakes more heavily.
Why use a train/test split?
Evaluating only on the same data used for fitting can be optimistic. A held-out test set provides a basic check of out-of-sample generalization. For time-series data, use a chronological split instead of random shuffling.
How does K-fold cross-validation select a model?
The training data are split into K folds. Each candidate degree is fitted K times, each time using K−1 folds and predicting the remaining fold. The average validation RMSE estimates predictive performance. Choose the degree before evaluating the separate test set. With small samples, fold-to-fold variability can be substantial.
What is the bias–variance tradeoff?
Simpler models can underfit systematic relationships (high bias), while more flexible models may become sensitive to random variation (high variance). A more complex model is not automatically worse: prefer repeated out-of-sample validation over degree alone.
Why can a high-degree polynomial overfit?
A flexible model may follow random noise instead of the underlying relationship. Compare training and test errors, and avoid extrapolating polynomials beyond the observed X range.
What are the limitations?
This browser tool handles one numeric predictor and one numeric outcome, using unregularized polynomial least squares. It does not infer causality, handle missing values, perform inference on coefficients, or establish which model will perform best on future data. Model selection uses cross-validation, not the final test set.