None .. note:: This tutorial was generated from an IPython notebook that can be downloaded `here <../../../source/notebooks/example_usage.ipynb>`_. .. _example_usage: Example usage ============= In this example we are predicting the 5th and 95th percentile and median of a toy dataset with a Random Forest Quantile Regressor, and the approximation regressor and comparing it to a general Random Forest Regressor. .. code:: python import numpy as np from sklearn.ensemble import RandomForestRegressor from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt from sklearn_quantile import ( RandomForestQuantileRegressor, SampleRandomForestQuantileRegressor, ) The base function ‘generating’ the observations .. code:: python def f(x): """The function to predict.""" return x * np.sin(x) Observations data are generated .. code:: python rng = np.random.RandomState(42) X = np.atleast_2d(rng.uniform(0, 10.0, size=1000)).T expected_y = f(X).ravel() sigma = 0.5 + X.ravel() / 10 noise = rng.lognormal(sigma=sigma) - np.exp(sigma ** 2 / 2) y = expected_y + noise X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) Models are initaliased, with the same common parameters to make the estimates comparable .. code:: python common_params = dict( max_depth=3, min_samples_leaf=4, min_samples_split=4, ) qrf = RandomForestQuantileRegressor(**common_params, q=[0.05, 0.5, 0.95]) qrf.fit(X_train, y_train) sqrf = SampleRandomForestQuantileRegressor(**common_params, q=[0.05, 0.5, 0.95]) sqrf.fit(X_train, y_train) rf = RandomForestRegressor(**common_params) rf.fit(X_train, y_train) .. parsed-literal:: Sampling trees .. raw:: html
RandomForestRegressor(max_depth=3, min_samples_leaf=4, min_samples_split=4)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
RandomForestRegressor(max_depth=3, min_samples_leaf=4, min_samples_split=4)