1. A method known as cross_val_predict() can be used to get scores of all instances in training set but instead of predictions you can set hyper-parameter to "decision_function".
2. In some cases you might need to set hyper-parameter to "predict_proba".
3. Then use precision recall curve function to compute precision and recall for all possible thresholds.
y_pred_scores = cross_val_predict(sgd_clf, X_train, y_train, cv = 3, method = 'decision_function')
precisions, recalls, thresholds = precision_recall_curve(y_train, y_pred_scores )
4. To plot all the scores a custom function can be used such as following:
def plot_precision_recall_vs_threshold(precisions, recalls, thresholds):
figure = plt.figure(figsize = [10, 7])
sns.lineplot(x = thresholds, y = precisions[:-1], legend = 'full')
sns.lineplot(x = thresholds, y = recalls[:-1], legend = 'full')
plt.legend(labels = ['Precision', 'Recall'], loc = 'center right', fontsize = 14)
plt.xlabel(xlabel = 'Threshold', size = 14)
plt.ylabel(ylabel = 'Score', size = 14)
plt.title(label = 'Precision Recall Scores vs Thresholds', size = 16)
plt.axis([-50000, 50000, 0, 1])
plt.grid(b = True)
plt.show()
plot_precision_recall_vs_threshold(precisions, recalls, thresholds)
Comments
0 comments
Article is closed for comments.