I have trained a random forest regression model using the sklearn package. I am now trying to export the confusion matrix, ROC curve, and precision-recall curve as PNG files. The relevant part of my code looks like this: #Set working directory i = "name" os.chdir(r"C:\Users\Me\\" + i) #Save confusion matrix cm = confusion_matrix(Y_test, test_prediction) cm_display = ConfusionMatrixDisplay(confusion_matrix = cm) cm_display.plot() plt.savefig('Confusion matrix - ' + i + '.png') plt.clf() #Save ROC curve ROC = RocCurveDisplay.from_estimator(model, X_test, Y_test, plot_chance_level = True) ROC.plot() plt.savefig('ROC curve - ' + i + '.png') plt.clf() #Save precision-recall curve PR = PrecisionRecallDisplay.from_estimator(model, X_test, Y_test, plot_chance_level = True) PR.plot() plt.savefig('Precision recall curve - ' + i + '.png') plt.clf() The working directory is definitely being set correctly, and the first two PNGs save correctly when the code is run. However, the third use of plt.savefig (trying to save the precision-recall curve) returns the following error: FileNotFoundError: [Errno 2] No such file or directory: I don't understand why this is. The directory clearly exists and can be found by matplotplib since it has just saved two files there. Does anyone know what might be causing this error please? Continue reading...