Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.metrics import roc_curve, auc
- C=np.linspace(1,100,10).tolist()
- train_results = []
- test_results = []
- for i in C:
- clf = LogisticRegression(C=i)
- clf.fit(tfX_train, y_train)
- train_pred = clf.predict(tfX_train)
- false_positive_rate, true_positive_rate, thresholds = roc_curve(y_train, train_pred)
- roc_auc = auc(false_positive_rate, true_positive_rate)
- train_results.append(roc_auc)
- y_pred = clf.predict(tfX_test)
- false_positive_rate, true_positive_rate, thresholds = roc_curve(y_test, y_pred)
- roc_auc = auc(false_positive_rate, true_positive_rate)
- test_results.append(roc_auc)
- from matplotlib.legend_handler import HandlerLine2D
- line1, = plt.plot(C, train_results,"b", label="Train AUC")
- line2, = plt.plot(C, test_results, "r", label="Test AUC")
- plt.legend(handler_map={line1: HandlerLine2D(numpoints=2)})
- plt.ylabel("AUC score")
- plt.xlabel("C")
- plt.grid(True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement