How to get the threshold from PrecisionRecallDisplay? My goal is to tune the Classifier with probability predict_proba() < threshold. Therefore, I need to get the threshold.
The problem is sklearn.metrics.PrecisionRecallDisplay do not give me the threshold.
scikit-learn.org
The code:
# Model Definition
rf_pipe_tuned = Pipeline(steps=[
    ('composer', composer),
    ('clf', RandomForestClassifier(
        max_depth=17, max_features=9, min_samples_split= 7, n_estimators=27
    ))
])

# Model Training
rf_pipe_tuned.fit(X=X_train, y=y_train)
print("done")

def isolate():
    display = PrecisionRecallDisplay.from_estimator(
        estimator=rf_pipe_tuned, X=X_test, y=y_test, name="RandomForestClassifier",
        pos_label="Attrited Customer"
    )
    _ = display.ax_.set_title("2-class Precision-Recall curve")

isolate()



PrecisionRecallDisplay() is just a very basic wrapper for sklearn.metrics.precision_recall_curve(). The latter returns numpy arrays for precision, recall and thresholds, which allow easy vectorized handling, e.g.:
precision, recall, thresholds = precision_recall_curve(target_test, probabilities)
f1_scores = 2 * recall * precision / (recall + precision)
best_thresh = thresholds[np.argmax(f1_scores)]

