Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- models = {
- 'SVM': SVC(kernel='linear', probability=True),
- 'Naive Bayes': GaussianNB(),
- 'Decision Tree': DecisionTreeClassifier(random_state=42),
- 'Random Forest': RandomForestClassifier(n_estimators=100, random_state=42),
- 'Gradient Boosting': GradientBoostingClassifier(n_estimators=100, random_state=42)
- }
- # Plot ROC curves
- plt.figure(figsize=(12, 8))
- for name, model in models.items():
- model.fit(X_train_scaled, y_train)
- if hasattr(model, "predict_proba"):
- probs = model.predict_proba(X_test_scaled)[:, 1]
- else:
- probs = model.decision_function(X_test_scaled)
- fpr, tpr, _ = roc_curve(y_test, probs)
- auc_score = roc_auc_score(y_test, probs)
- plt.plot(fpr, tpr, label=f'{name} (AUC = {auc_score:.2f})')
- # Reference line for random guess
- plt.plot([0, 1], [0, 1], 'k--')
- plt.title('ROC Curves of ML Models (Titanic Example)', fontsize=14)
- plt.xlabel('False Positive Rate')
- plt.ylabel('True Positive Rate')
- plt.legend()
- plt.grid(True)
- plt.tight_layout()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement