.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_quantile_mlpregression.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_quantile_mlpregression.py: Quantile MLPRegressor ===================== `scikit-learn `_ does not have a quantile regression for multi-layer perceptron. `mlinsights `_ implements a version of it based on the *scikit-learn* model. The implementation overwrites method ``_backprop``. We first generate some dummy data. .. GENERATED FROM PYTHON SOURCE LINES 13-28 .. code-block:: Python import numpy from pandas import DataFrame import matplotlib.pyplot as plt from sklearn.neural_network import MLPRegressor from mlinsights.mlmodel import QuantileMLPRegressor X = numpy.random.random(1000) eps1 = (numpy.random.random(900) - 0.5) * 0.1 eps2 = (numpy.random.random(100)) * 10 eps = numpy.hstack([eps1, eps2]) X = X.reshape((1000, 1)) Y = X.ravel() * 3.4 + 5.6 + eps .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. code-block:: Python clr = MLPRegressor(hidden_layer_sizes=(30,), activation="tanh") clr.fit(X, Y) .. raw:: html
MLPRegressor(activation='tanh', hidden_layer_sizes=(30,))
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 37-42 .. code-block:: Python clq = QuantileMLPRegressor(hidden_layer_sizes=(30,), activation="tanh") clq.fit(X, Y) .. raw:: html
QuantileMLPRegressor(activation='tanh', hidden_layer_sizes=(30,))
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 44-50 .. code-block:: Python data = dict(X=X.ravel(), Y=Y, clr=clr.predict(X), clq=clq.predict(X)) df = DataFrame(data) df.head() .. raw:: html
X Y clr clq
0 0.379957 6.937997 7.492150 6.949007
1 0.076410 5.860495 6.348967 5.788681
2 0.292278 6.559855 7.178483 6.630396
3 0.755102 8.211254 8.671232 8.156544
4 0.637990 7.733815 8.331789 7.806592


.. GENERATED FROM PYTHON SOURCE LINES 52-66 .. code-block:: Python fig, ax = plt.subplots(1, 1, figsize=(10, 4)) choice = numpy.random.choice(X.shape[0] - 1, size=100) xx = X.ravel()[choice] yy = Y[choice] ax.plot(xx, yy, ".", label="data") xx = numpy.array([[0], [1]]) y1 = clr.predict(xx) y2 = clq.predict(xx) ax.plot(xx, y1, "--", label="L2") ax.plot(xx, y2, "--", label="L1") ax.set_title("Quantile (L1) vs Square (L2) for MLPRegressor") ax.legend() .. image-sg:: /auto_examples/images/sphx_glr_plot_quantile_mlpregression_001.png :alt: Quantile (L1) vs Square (L2) for MLPRegressor :srcset: /auto_examples/images/sphx_glr_plot_quantile_mlpregression_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.405 seconds) .. _sphx_glr_download_auto_examples_plot_quantile_mlpregression.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_quantile_mlpregression.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_quantile_mlpregression.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_quantile_mlpregression.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_