def submitAccuracy():
    accuracy = NBAccuracy(features_train, labels_train, features_test,
                          labels_test)
    return accuracy
### in together--separate them so we can give them different colors in the scatterplot,
### and visually identify them
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)
accuracy = NBAccuracy(features_train, labels_train, features_test, labels_test)

### draw the decision boundary with the text points overlaid
prettyPicture(clf, features_test, labels_test)

print(accuracy)
#print(labels_test[0:5]-labels_test[1:6])
#output_image("test.png", "png", open("test.png", "rb").read())
示例#3
0
from class_vis import prettyPicture
from prep_terrain_data import makeTerrainData
from ClassifyNB import NBAccuracy
from ClassifySVM import SVMAccuracy

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

features_train, labels_train, features_test, labels_test = makeTerrainData()
print(
    'NB:' +
    str(NBAccuracy(features_train, labels_train, features_test, labels_test)))
print(
    'SVM:' +
    str(SVMAccuracy(features_train, labels_train, features_test, labels_test)))