.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "glr_examples/view/plot_model.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_glr_examples_view_plot_model.py: ================================================= Plot model ================================================= plots model results 'y' (true labels) versus 'ypred' (predicted) from test data. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python # Author: L.Kouadio # Licence: BSD-3-clause .. GENERATED FROM PYTHON SOURCE LINES 12-16 The plots is a great alternative to know where estimator/classifier fails to predict correctly the target. * Prepare our data - Use analysis data of Bagoue dataset since data is alread scaled and imputed .. GENERATED FROM PYTHON SOURCE LINES 16-65 .. code-block:: Python from watex.exlib.sklearn import SVC from watex.datasets import fetch_data from watex.utils.mlutils import split_train_test_by_id from watex.view import plotModel X, y = fetch_data('bagoue analysis' ) _, Xtest = split_train_test_by_id(X, test_ratio=.3 , # 30% in test set keep_colindex= False ) _, ytest = split_train_test_by_id(y, .3 , keep_colindex =False) # * prepared our demo estimator and plot model predicted svc_clf = SVC(C=100, gamma=1e-2, kernel='rbf', random_state =42) base_plot_params ={ 'lw' :3., # line width 'lc':(.9, 0, .8), 'ms':7., 'yp_marker' :'o', 'fig_size':(12, 8), 'font_size':15., 'xlabel': 'Test examples', 'ylabel':'Flow categories' , 'marker':'o', 'markeredgecolor':'k', 'markerfacecolor':'b', 'markeredgewidth':3, 'yp_markerfacecolor' :'k', 'yp_markeredgecolor':'r', 'alpha' :1., 'yp_markeredgewidth':2., 'show_grid' :True, 'galpha' :0.2, 'glw':.5, 'rotate_xlabel' :90., 'fs' :3., 's' :20 , 'rotate_xlabel':90 } plotModel(yt= ytest , Xt=Xtest , predict =True , # predict the result (estimator fit) clf=svc_clf , fill_between= False, prefix ='b', labels=['FR0', 'FR1', 'FR2', 'FR3'], # replace 'y' labels. **base_plot_params ) # plot shows where the model failed to predict the target 'yt' .. image-sg:: /glr_examples/view/images/sphx_glr_plot_model_001.png :alt: plot model :srcset: /glr_examples/view/images/sphx_glr_plot_model_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/watex/envs/0.3.2/lib/python3.10/site-packages/sklearn/utils/validation.py:1300: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.312 seconds) .. _sphx_glr_download_glr_examples_view_plot_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/watex/watex/0.3.X?urlpath=lab/tree/notebooks/glr_examples/view/plot_model.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_model.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_model.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_