# precision recall curve

from sklearn.metrics import precision_recall_curve, average_precision_score import matplotlib.pyplot as plt from sklearn.datasets import load_breast_cancer from sklearn.neural_network import MLPClassifier from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_test_split #Dataset cancer_dataset = load_breast_cancer() X=cancer_dataset.data y=cancer_dataset.target #Model Implementation mlp = MLPClassifier(max_iter=500) # Split data into 50% train and 50% test subsets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, shuffle=False) # Learn the digits on the train subset mlp.fit(X_train, y_train) # Predict the value of the digit on the test subset predicted = mlp.predict(X_test) # Calculate precision-recall curve precision, recall, thresholds = precision_recall_curve(y_test, predicted) # Calculate average precision average_precision = average_precision_score(y_test, predicted) # Plot precision-recall curve plt.step(recall, precision, where="post") plt.xlabel("Recall") plt.ylabel("Precision") plt.title("Precision-Recall Curve (AP={:.2f})".format(average_precision)) plt.show()