JGuizard
4/8/2016 - 3:35 PM

Get a classification accuracy

Get a classification accuracy

def get_classification_accuracy(model, data, true_labels):
    # First get the predictions
    ## YOUR CODE HERE
    prds = model.predict(data, output_type='margin')
    print prds
    # Compute the number of correctly classified examples
    ## YOUR CODE HERE
    correct=0
    for i in range(0,len(prds)):
        if(prds[i]>=0 and true_labels[i]==1):
            correct+=1
        elif(prds[i]<0 and true_labels[i]==-1):
            correct+=1

    # Then compute accuracy by dividing num_correct by total number of examples
    ## YOUR CODE HERE
    accuracy=float(correct)/float(len(true_labels))
    
    return accuracy