# predict using your classifier
predicted = linear.predict(X_test)


print confusion_matrix(Y_test, predicted)

cm = confusion_matrix(Y_test, predicted)
plt.matshow(cm)
plt.title('Confusion matrix of the classifier')
plt.colorbar()
plt.xlabel('Predicted')
plt.ylabel('True')
plt.show()

print classification_report(Y_test, predicted)

correct = predicted == Y_test
print ' correct: ', np.sum(correct)/float(len(correct))
print 'Recall:' ,recall_score(Y_test, predicted, average='weighted')
print 'Precision:' ,precision_score(Y_test, predicted, average='weighted')  
print 'F1 Score:',f1_score(Y_test, predicted, average='weighted') 
 

print 'Multiple:', custom.multiple_auc(Y_test, predicted)

<<<<<<< HEAD

=======
>>>>>>> ac195d198eac27320f60507608881b9c0e4bed2a
# NaivB.fit(X_next, Y_next)  
linear.fit(X_next, Y_next)                      


X_valid = X_valid.astype(np.float)
X_valid[np.isnan(X_valid)] = 0
predicted = linear.predict(X_valid)   
correct = predicted == Y_valid
print ' correct: ', np.sum(correct)/float(len(correct))

print confusion_matrix(Y_valid, predicted)
cm = confusion_matrix(Y_valid, predicted)
plt.matshow(cm)
plt.title('Confusion matrix of the classifier')
plt.colorbar()
pl.xlabel('Predicted')
pl.ylabel('True')
plt.show()

print 'Recall:' ,recall_score(Y_valid, predicted, average='weighted')
print 'Precision:' ,precision_score(Y_valid, predicted, average='weighted')  
print 'Multiple:', custom.multiple_auc(Y_valid, predicted)
 





Esempio n. 3
0
        raise Exception('not enough arguments')

    MODE = sys.argv[1] # cross vs per
    MAX_EPOCH = int(sys.argv[2]) # max epochs
    TRAIN_SIZE2 = int(sys.argv[3]) # the sample size to train with 
    LEARNING_RATE = float(sys.argv[4])
    ARCHITECTURE = int(sys.argv[5])
    if ARCHITECTURE == 1:
        net = create_net
    elif ARCHITECTURE == 2:
        net = create_net2
    else:
        net = create_net3

    if MODE == 'per':
        print 'Training per patient classifier'
        # train_info = train_all(create_net, max_epochs=25) # Training for longer would likley be better
        Y_true, Y_pred = train_subject_specific(net, subject_id=[ 2 ], train_series_ids=range(1,8), \
            test_series_ids=range(8,9), train_sample_size=TRAIN_SIZE2, max_epochs=MAX_EPOCH, learning_rate=LEARNING_RATE)
    elif MODE == 'cross':
        print 'Training cross patient classifier'
        Y_true, Y_pred = train_cross_subject(net, range(1,9), range(1,5), \
            range(9,11), range(2,3), max_epochs=MAX_EPOCH, \
            train_sample_size=TRAIN_SIZE2, learning_rate=LEARNING_RATE)


    print 'multiple_auc:',multiple_auc(Y_true, Y_pred)
    print classification_report(Y_true, Y_pred)
    print confusion_matrix(Y_true, Y_pred)
    # make_submission(train_info, "naive_grasp.csv")