help="path where trained classifier was saved") parser.add_option( "-r", "--result", action="store", dest="result", default="roc", help="path of the saved roc figure, make sure the folder exists") options, args = parser.parse_args(sys.argv) with open(options.path, 'rb') as f: classifier = pickle.load(f) y_test_prob = [] y_test = [] for X, y in parse_svm_light_data(sys.stdin): y_prob = classifier.predict_prob(X) y_test.append(y) y_test_prob.append(y_prob) fpr, tpr, _ = roc_curve(y_test, y_test_prob) roc_auc = auc(fpr, tpr) # Plot of a ROC curve for a specific class plt.figure() plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc) plt.plot([0, 1], [0, 1], 'k--') plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate')
if __name__ == '__main__': parser = OptionParser() parser.add_option("-m", "--model-path", action="store", dest="path", default="models", help="path where trained classifiers are saved") parser.add_option("-r", "--result", action="store", dest="result", default="roc", help="name of the figure") options, args = parser.parse_args(sys.argv) files = [options.path + "/" + filename for filename in os.listdir(options.path) if filename.startswith('part')] classifiers = map(load_model, files) y_test_prob = [] y_test = [] for X, y in parse_svm_light_data(sys.stdin): y_prob = predict_prob(classifiers, X) y_test.append(y) y_test_prob.append(y_prob) fpr, tpr, _ = roc_curve(y_test, y_test_prob) roc_auc = auc(fpr, tpr) # Plot of a ROC curve for a specific class plt.figure() plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc) plt.plot([0, 1], [0, 1], 'k--') plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate')