Link to the notebook at the end of this post

Quantile regression is a powerful statistical technique that estimates the conditional quantiles of a response variable, providing a more comprehensive view of the relationship between variables than traditional mean regression. While linear quantile regression is well-established, performing quantile regression with any machine learning regressor is less common but highly valuable.

In this blog post, we’ll explore how to perform quantile regression in R and Python using RandomForestRegressor, RidgeCV, and KNeighborsRegressor with the help of nnetsauce, a package that extends scikit-learn models with additional functionalities.

Why Quantile Regression?

Traditional regression models (e.g., linear regression) predict the mean of the dependent variable given the independent variables. However, in many real-world scenarios, we might be interested in:

  • Predicting extreme values (e.g., high or low sales, extreme temperatures).
  • Assessing uncertainty by estimating prediction intervals.
  • Handling non-Gaussian distributions where mean regression may be insufficient.

Quantile regression allows us to estimate any quantile (e.g., 5th, 50th, 95th percentiles) of the response variable, offering a more robust analysis.

Quantile Regression with nnetsauce

The nnetsauce package provides a flexible way to perform quantile regression using any scikit-learn regressor. Below, we’ll demonstrate how to use it with three different models, in R and Python:

  • RandomForestRegressor
  • RidgeCV (linear regression with cross-validated regularization)
  • KNeighborsRegressor
2025_05_20_quantile_regression

Open In Colab

Comments powered by Talkyard.