예제 #1
0
def evaluate_results(pred_test, pred_train, labels_test, labels_train, name):
    accuracy_test = accuracy_score(labels_test, pred_test)
    accuracy_train = accuracy_score(labels_train, pred_train)
    fig = prettyPicture(clf, features_test, labels_test)
    save_fig(fig, name, 'Decision_Tree/images')
    print(
        name, 'test accuracy {}:, train accuracy {}:'.format(
            round(accuracy_test, 3), round(accuracy_train, 3)))
    print('confusion_matrix {}:'.format(
        confusion_matrix(labels_test, pred_test)))
예제 #2
0
clf.fit(features_train, labels_train)

# predict train and test
pred_train = clf.predict(features_train)
pred_test = clf.predict(features_test)

# calculate accuracy
accuracy_test = accuracy_score(labels_test, pred_test)
accuracy_train = accuracy_score(labels_train, pred_train)
print(
    name,
    'test accuracy {}:, train accuracy {}:'.format(round(accuracy_test, 3),
                                                   round(accuracy_train, 3)))

# plot the classes
fig = prettyPicture(clf, features_test, labels_test)
save_fig(fig, name, 'Decision_Tree/images')

# confusion matrix
print('confusion_matrix {}:'.format(confusion_matrix(labels_test, pred_test)))
print(classification_report(labels_test, pred_test, labels=[0, 1]))

# plot roc curve
y_test_pred_prob = clf.predict_proba(features_test)[:, 1]

# IMPORTANT: first argument is true values, second argument is predicted probabilities
fpr, tpr, thresholds = roc_curve(labels_test, pred_test)

plt.figure()
plt.plot(fpr, tpr)
plt.xlim([0.0, 1.0])