From d8898598ba82bc690915d8e2bf366e2579532adf Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 1 May 2026 14:32:22 +0200 Subject: [PATCH] feature(algo): add randomforest algorithm to the comparison --- ML/aufgaben/comparison/compare.txt | 35 +++++++++++++++++++ .../comparison/compare_ml_algorihms.py | 2 ++ 2 files changed, 37 insertions(+) diff --git a/ML/aufgaben/comparison/compare.txt b/ML/aufgaben/comparison/compare.txt index 46d136b..5e83e7a 100644 --- a/ML/aufgaben/comparison/compare.txt +++ b/ML/aufgaben/comparison/compare.txt @@ -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 diff --git a/ML/aufgaben/comparison/compare_ml_algorihms.py b/ML/aufgaben/comparison/compare_ml_algorihms.py index ad79f1d..d11658c 100644 --- a/ML/aufgaben/comparison/compare_ml_algorihms.py +++ b/ML/aufgaben/comparison/compare_ml_algorihms.py @@ -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)