.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_classifier.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_classifier.py: ============================================ Fitting and evaluating an ICR Random Forest ============================================ In this example we fit and evaluate an :class:`icrlearn.ICRRandomForestClassifier` on the Iris dataset. .. GENERATED FROM PYTHON SOURCE LINES 11-12 Load the Iris dataset and split it into training and test sets .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: Python from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) .. GENERATED FROM PYTHON SOURCE LINES 20-21 Train an ICRRandomForestClassifier on the training set .. GENERATED FROM PYTHON SOURCE LINES 21-25 .. code-block:: Python from icrlearn import ICRRandomForestClassifier clf = ICRRandomForestClassifier().fit(X_train, y_train) .. GENERATED FROM PYTHON SOURCE LINES 26-27 Evaluate the classifier on the test set and print some metrics .. GENERATED FROM PYTHON SOURCE LINES 27-33 .. code-block:: Python from sklearn.metrics import classification_report y_pred = clf.predict(X_test) classification_report = classification_report(y_test, y_pred) print(classification_report) .. rst-class:: sphx-glr-script-out .. code-block:: none precision recall f1-score support 0 1.00 1.00 1.00 10 1 0.73 1.00 0.84 8 2 1.00 0.75 0.86 12 accuracy 0.90 30 macro avg 0.91 0.92 0.90 30 weighted avg 0.93 0.90 0.90 30 .. GENERATED FROM PYTHON SOURCE LINES 34-35 Plot a confusion matrix of the classifier's predictions .. GENERATED FROM PYTHON SOURCE LINES 35-44 .. code-block:: Python import matplotlib.pyplot as plt import seaborn as sns from sklearn.metrics import confusion_matrix conf_matr = confusion_matrix(y_test, y_pred) sns.heatmap(conf_matr, annot=True) plt.xlabel("Predicted") plt.ylabel("True") plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_classifier_001.png :alt: plot classifier :srcset: /auto_examples/images/sphx_glr_plot_classifier_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.616 seconds) .. _sphx_glr_download_auto_examples_plot_classifier.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_classifier.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_classifier.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_classifier.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_