Note
Go to the end to download the full example code.
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
Train an ICRRandomForestClassifier on the training set
from icrlearn import ICRRandomForestClassifier
clf = ICRRandomForestClassifier().fit(X_train, y_train)
Evaluate the classifier on the test set and print some metrics
from sklearn.metrics import classification_report
y_pred = clf.predict(X_test)
classification_report = classification_report(y_test, y_pred)
print(classification_report)
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()

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