def submitClassify():

    clf = classify(features_train, labels_train)

    ### draw the decision boundary with the text points overlaid
    try:
        prettyPicture(clf, features_test, labels_test)
        output_image("test.png", "png", open("test.png", "rb").read())
    except NameError:
        pass
Exemple #2
0
def main():
    features_train, labels_train, features_test, labels_test = makeTerrainData(
    )

    ### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
    ### 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.
    gamma, c = 'auto', 1.0

    kernel = raw_input('Select the kernel: ')
    if (kernel != 'linear'):
        gamma = raw_input('Gamma: ')
        c = raw_input('C: ')

    clf = classify(features_train, labels_train, kernel, c, gamma)
    print('Python SVM Example')

    accuracy = clf.score(features_test, labels_test)
    print('Accuracy score: {}'.format(accuracy))

    ### draw the decision boundary with the text points overlaid
    prettyPicture(clf, features_test, labels_test)
    output_image("naive_bayes.png", "png",
                 open("naive_bayes.png", "rb").read())
    os.system('display naive_bayes.png &')
Exemple #3
0
features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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)

### 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())
import pylab as pl


features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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]



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())


# Accuracy
# method 1
pred = clf.predict(features_test)
accuracy = sum(labels_test == pred) / float(len(labels_test))
print("Accuracy is: ", accuracy)

# method 2
from sklearn.metrics import accuracy_score
Exemple #5
0
from prep_terrain_data import makeTerrainData
from class_vis import prettyPicture, output_image
from ClassifyNB import classify

import numpy as np
import pylab as pl

features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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.
classifier = classify(features_train, labels_train)
print classifier.score(features_test, labels_test)

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




Exemple #6
0
features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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, features_test, labels_test)

### 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())
Exemple #7
0
features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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.
classifier = classify(features_train, labels_train)
print classifier.score(features_test, labels_test)

### draw the decision boundary with the text points overlaid
prettyPicture(classifier, features_test, labels_test)
# output_image("test.png", "png", open("test.png", "rb").read())
Exemple #8
0
    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.
# Instantiate, then get or return the Naive Bayes Gaussain TRAINED classifier
clf = classify('NB', features_train, labels_train)
# print("\ttype(clf) - {}\n".format(type(clf))) # class 'sklearn.naive_bayes.GaussianNB

# Instantiate, then get or return the SupportVectorMachines TRAINED classifier
SVMclf = classify('SVM', features_train, labels_train)

# use the trained classifier to do the predictions
# generate the ** pred ** numpy.ndarray (n dimensional array)
# how to time something, performance timing
t0 = time.time()
pred = clf.predict(features_test)  # used for accuracy methods 2 and 3 below
print("Naive Bayes, predict timing: - {}".format(round(time.time() - t0, 3)))
# print("\tpred is {}\n".format(pred))
# print("\ttype(pred) - {}\n".format(type(pred))) # numpy.ndarray

# generate Support Vector Machines - SVM - predictor
Exemple #9
0
from ..bin.prep_terrain_data import makeTerrainData
from ..bin.class_vis import prettyPicture, output_image
from ClassifyNB import classify
#from classify import NBAccuracy

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

#from pprintpp import pprint
#pprint(makeTerrainData())

features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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]


clf, accuracy = classify(features_train, labels_train, features_test, labels_test)


### 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())
print "Classification accuracy = ", accuracy

from prep_terrain_data import makeTerrainData
from class_viz import prettyPicture, output_image
from ClassifyNB import classify

import numpy as np
import pylab as pl


features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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,features_test, labels_test)



### 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())
def classify(features_train, labels_train):   
    ### import the sklearn module for GaussianNB
    ### create classifier
    ### fit the classifier on the training features and labels
    ### return the fit classifier
    
        
    ### your code goes here!
import numpy as np
import pylab as pl


features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow" points mixed
### 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)



### 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())