Exemple #1
0
    if labels_train[ii] == 0
]
grade_slow = [
    features_train[ii][0] for ii in range(0, len(features_train))
    if labels_train[ii] == 1
]
bumpy_slow = [
    features_train[ii][1] for ii in range(0, len(features_train))
    if labels_train[ii] == 1
]

clf = classify(features_train, labels_train)

# draw the decision boundary with the text points overlaid
prettyPicture(clf, features_test, labels_test)
output_image("test.png", "png", open("test.png", "rb").read())

# compare tha accuracy by hand
count = 0.0  # have to be in floating point
predict = clf.predict(features_test)
for i in range(0, len(predict)):
    if predict[i] == labels_test[i]:
        count += 1
accuracy = count / (len(predict))
print 'self-calculate: ', accuracy
# using built-in function of sklearn
acc = NBAccuracy(features_train, labels_train, features_test, labels_test)
print 'using clf.score: ', acc
# or
print 'accuracy_score function', accuracy_score(predict, labels_test)
def submitAccuracy():
    accuracy = NBAccuracy(features_train, labels_train, features_test,
                          labels_test)
    return accuracy
grade_fast = [
    features_train[ii][0] for ii in range(0, len(features_train))
    if labels_train[ii] == 0
]
bumpy_fast = [
    features_train[ii][1] for ii in range(0, len(features_train))
    if labels_train[ii] == 0
]
grade_slow = [
    features_train[ii][0] for ii in range(0, len(features_train))
    if labels_train[ii] == 1
]
bumpy_slow = [
    features_train[ii][1] for ii in range(0, len(features_train))
    if labels_train[ii] == 1
]

# You will need to complete this function imported from the ClassifyNB script.
# Be sure to change to that code tab to complete this quiz.
clf = classify(features_train, labels_train)

### draw the decision boundary with the text points overlaid
#prettyPicture(clf, features_test, labels_test)
#output_image("test.png", "png", open("test.png", "rb").read())

pred = clf.predict(features_test)

from classify import NBAccuracy
# below are the two ways accuracy can be found
print "Accuracy is: {}".format(NBAccuracy(clf, pred, labels_test))
print "Accuracy is: {}".format(clf.score(features_test, labels_test))
Exemple #4
0
from class_vis import prettyPicture
from prep_terrain_data import makeTerrainData
from classify import NBAccuracy

import matplotlib.pyplot as plt
import numpy as np
import pylab as pl

features_train, labels_train, features_test, labels_test = makeTerrainData()


def submitAccuracy():
    accuracy = NBAccuracy(features_train, labels_train, features_test,
                          labels_test)
    return accuracy


if __name__ == "__main__":
    print "NBGaussian accuracy:", NBAccuracy(features_train, labels_train,
                                             features_test, labels_test)
Exemple #5
0
def submitAccuracy():
    accuracy = NBAccuracy(features_train, labels_train, features_test,
                          labels_test)
    print("accuracy: ", accuracy)
    return accuracy
def submitAccuracy():
    accuracy = NBAccuracy(features_train, labels_train, features_test, labels_test, 2)
    #return (accuracy)
    print(accuracy)