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        13
           1       0.75      1.00      0.86         6
           2       1.00      0.82      0.90        11

    accuracy                           0.93        30
   macro avg       0.92      0.94      0.92        30
weighted avg       0.95      0.93      0.93        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.838 seconds)

Gallery generated by Sphinx-Gallery