Fitting and evaluating an ICR Random Forest#

In this example we fit and evaluate an icrlearn.ICRRandomForestClassifier on the Iris dataset.

Load the Iris dataset and split it into training and test sets

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)

Train an ICRRandomForestClassifier on the training set

Evaluate the classifier on the test set and print some metrics

              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

Plot a confusion matrix of the classifier’s predictions

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()
plot classifier

Total running time of the script: (0 minutes 1.616 seconds)

Gallery generated by Sphinx-Gallery