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()
Ejemplo n.º 2
0
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.roc(y_true, y_score)
def test_roc():
    plot.roc(y_test, y_score)
def test_roc_y_score_vector():
    plot.roc(y_test, y_score_vector)
Ejemplo n.º 5
0
 def test_roc(self):
     with self.assertRaisesRegexp(ValueError, "needed to plot"):
         plot.roc([1, 0], None)
def test_roc_y_score_vector():
    plot.roc(y_test, y_score_vector)
def test_roc():
    plot.roc(y_test, y_score)
    def evaluate_p(self, y, y_score):

        plot.precision_recall(y, y_score)
        plt.show()
        plot.roc(y, y_score)
        plt.show()
plt.step(recall,
         precision,
         color='b',
         where='post',
         label=r'Average Precision = %0.4f' % (average_precision))
plt.fill_between(recall, precision, step='post', alpha=0.2, color='b')

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