feature(algo): add randomforest algorithm to the comparison

This commit is contained in:
2026-05-01 14:32:22 +02:00
parent ab483da421
commit d8898598ba
2 changed files with 37 additions and 0 deletions
+35
View File
@@ -31,6 +31,20 @@ Adj. Rand: 0.943
weighted avg 0.98 0.98 0.98 45
--- Random Forest ---
Accuracy: 1.000
Adj. Rand: 1.000
precision recall f1-score support
setosa 1.00 1.00 1.00 19
versicolor 1.00 1.00 1.00 13
virginica 1.00 1.00 1.00 13
accuracy 1.00 45
macro avg 1.00 1.00 1.00 45
weighted avg 1.00 1.00 1.00 45
--- K-Means (mapped) ---
Accuracy: 0.893
Adj. Rand: 0.730
@@ -91,6 +105,27 @@ Adj. Rand: 0.710
weighted avg 0.88 0.85 0.85 540
--- Random Forest ---
Accuracy: 0.976
Adj. Rand: 0.946
precision recall f1-score support
0 1.00 0.98 0.99 53
1 0.96 1.00 0.98 50
2 1.00 1.00 1.00 47
3 0.98 0.96 0.97 54
4 0.97 1.00 0.98 60
5 0.97 0.95 0.96 66
6 0.98 0.98 0.98 53
7 0.98 0.98 0.98 55
8 0.95 0.95 0.95 43
9 0.97 0.95 0.96 59
accuracy 0.98 540
macro avg 0.98 0.98 0.98 540
weighted avg 0.98 0.98 0.98 540
--- K-Means (mapped) ---
Accuracy: 0.794
Adj. Rand: 0.667
@@ -15,6 +15,7 @@ from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.cluster import KMeans
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report, adjusted_rand_score
import numpy as np
@@ -64,6 +65,7 @@ def evaluate(name, dataset, target_names):
for classifier_name, classifier in [
("Decision Tree", DecisionTreeClassifier(random_state=42)),
("Naive Bayes", GaussianNB()),
("Random Forest", RandomForestClassifier(n_estimators=100, random_state=42)),
]:
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)