import matplotlib.pyplot as plt
from sklearn.metrics import RocCurveDisplay
# Your model training and evaluation steps here...
# Assuming you already have your model, X_test, and y_test
# Create a plot
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
# Plot ROC Curve
roc_display = RocCurveDisplay.from_estimator(model, X_test, y_test, ax=axes[2])
# Specify the threshold you want to highlight
threshold_to_highlight = 0.5 # for example, the threshold
# Get the false positive rates, true positive rates, and thresholds
fpr = roc_display.fpr
tpr = roc_display.tpr
thresholds = roc_display.thresholds
# Find the index of the threshold closest to your specified threshold
idx = (np.abs(thresholds - threshold_to_highlight)).argmin()
# Plot the threshold point
axes[2].scatter(fpr[idx], tpr[idx], color='red', s=100, zorder=5, label='Threshold = {:.2f}'.format(threshold_to_highlight))
# Display legend
axes[2].legend()
# Show plot
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, RocCurveDisplay
# Your model training and evaluation steps here...
# Assuming you already have your model, X_test, and y_test
# Obtain predictions probabilities (assuming binary classification)
y_scores = model.predict_proba(X_test)[:, 1] # Get the probability of the positive class
# Compute ROC curve
fpr, tpr, thresholds = roc_curve(y_test, y_scores)
# Create a plot
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
# Plot ROC Curve
roc_display = RocCurveDisplay(fpr=fpr, tpr=tpr).plot(ax=axes[2])
# Specify the threshold you want to highlight
threshold_to_highlight = 0.5 # for example
# Find the index of the threshold closest to your specified threshold
idx = (np.abs(thresholds - threshold_to_highlight)).argmin()
# Plot the threshold point
axes[2].scatter(fpr[idx], tpr[idx], color='red', s=100, zorder=5,
label='Threshold = {:.2f}'.format(threshold_to_highlight))
# Display legend
axes[2].legend()
# Show plot
plt.show()