Last active
January 24, 2024 04:16
-
-
Save wibowotangara/56b26d7459b19383003188733da887e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.metrics import confusion_matrix | |
from sklearn.metrics import accuracy_score, classification_report | |
results = {} | |
models = { | |
'Random Forest': RandomForestClassifier(random_state=42), | |
'Logistic Regression': LogisticRegression(random_state=42), | |
'Decision Tree': DecisionTreeClassifier(random_state=42), | |
'Gradient Boosting': GradientBoostingClassifier(random_state=42), | |
'K-Nearest Neighbors': KNeighborsClassifier(), | |
} | |
classification_reports = {} | |
model_names = [] | |
accuracies = [] | |
for model_name, model in models.items(): | |
print(f"Training {model_name}...") | |
model.fit(X_train, Y_train) | |
print(f"Evaluating {model_name}...") | |
Y_pred = model.predict(X_test) | |
confusion = confusion_matrix(Y_test, Y_pred) | |
classification_rep = classification_report( | |
Y_test, Y_pred, target_names=['Good', 'Bad'], zero_division=1 | |
) | |
classification_reports[model_name] = classification_rep | |
accuracy = accuracy_score(Y_test, Y_pred) | |
model_names.append(model_name) | |
accuracies.append(accuracy) | |
print("\nClassification Report:") | |
print(classification_rep) | |
print(f"{model_name} Accuracy: {accuracy:.4f}") | |
print("=" * 50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment