def evaluate_p(self, y, y_score_list,path): fig, ax = plt.subplots() for y_score in y_score_list: plot.roc(y, y_score,ax=ax) handles, labels=ax.get_legend_handles_labels() # plt.setp(handles,linewidth=1.0) ax.legend(handles=handles,labels=self.models_name,loc="lower right") fig.savefig(path+'_roc.png') plt.show() fig, ax = plt.subplots() for y_score in y_score_list: plot.precision_recall(y, y_score,ax=ax) ax.legend(self.models_name,loc='upper right') fig.savefig(path + 'precision_recall.png') plt.show()
def test_precision_recall(): plot.precision_recall(y_test, y_score)
def test_precision_recall_y_score_vector(): plot.precision_recall(y_test, y_score_vector)
def test_precision_recall(self): with self.assertRaisesRegexp(ValueError, "needed to plot"): plot.precision_recall(None, None)
import matplotlib.pyplot as plt from sklearn import datasets from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from sklearn_evaluation import plot data = datasets.make_classification(200, 10, n_informative=5, class_sep=0.65) X = data[0] y = data[1] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) est = RandomForestClassifier() est.fit(X_train, y_train) y_pred = est.predict(X_test) y_score = est.predict_proba(X_test) y_true = y_test plot.precision_recall(y_true, y_score) plt.show()
def evaluate_p(self, y, y_score): plot.precision_recall(y, y_score) plt.show() plot.roc(y, y_score) plt.show()
plt.xlabel('Recall') plt.ylabel('Precision') plt.ylim([0.0, 1.01]) plt.xlim([0.0, 1.01]) plt.legend(loc="lower right") plt.savefig('SVM-PrecisionRecallCurve_Average.pdf', format='pdf') plt.show() skplot.roc(y_all_test, y_all_score1) figure = plt.gcf() figure.set_size_inches(6, 6) plt.savefig('SVM-ROCCurve.pdf', format='pdf') plt.show() skplot.precision_recall(y_all_test, y_all_score1) figure = plt.gcf() figure.set_size_inches(6, 6) plt.savefig('SVM-PrecisionRecallCurve.pdf', format='pdf') plt.show() print("Plotting the confusion matrix normalized") conf_mat_norm = conf_mat / np.sum(conf_mat, axis=1) # Normalizing the confusion matrix figure = plt.gcf() figure.set_size_inches(2, 2) sns.set(font_scale=1.25) hm = sns.heatmap(conf_mat, cbar=False, annot=True,
import matplotlib.pyplot as plt from sklearn import datasets from sklearn.ensemble import RandomForestClassifier from sklearn.cross_validation import train_test_split from sklearn_evaluation import plot data = datasets.make_classification(200, 10, 5, class_sep=0.65) X = data[0] y = data[1] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) est = RandomForestClassifier() est.fit(X_train, y_train) y_pred = est.predict(X_test) y_score = est.predict_proba(X_test) y_true = y_test plot.precision_recall(y_true, y_score)