I have chosen threshold value with below code to get 90% precision classifier
from sklearn.model_selection import cross_val_predict y_train_pred = cross_val_predict(sgd_clf, X_train, y_train, cv=3) z_scores = cross_val_predict(sgd_clf, X_train, y_train, method='decision_function') from sklearn.metrics import precision_recall_curve precisions, recalls, thresholds = precision_recall_curve(y_train_pred, z_scores) threshold_90_precision = thresholds[np.argmax(precisions >= 0.9)] y_train_pred_90percent_precision = (z_scores >= threshold_90_precision) print(precision_score(y_train, y_train_pred_90percent_precision))
I'm expecting precision_score to be 90% but it returned 95%. Is this expected? Anything incorrect with my code? If it's expected, can you please explain the reason?