Exemplo n.º 1
0
def draw_svm_db(kernel="linear", gamma=1000, C=1.0):
    
    #Train
    X_train, X_test, y_train, y_test = mytools.make_fake_data()
    clf = SVC(kernel=kernel, gamma=gamma, C=C)
    start = time.time()
    clf.fit(X_train, y_train)
    train_time = time.time() - start
    
    #Predict
    start = time.time()
    preds = clf.predict(X_test)
    test_time = time.time() - start 
    
    #Score
    accuracy = accuracy_score(y_test, preds)
    
    print ""
    print "Kernel: ", kernel
    print "C: ", C, " , gamma: ", gamma
    print "Accuracy: ", accuracy
    print "Training time: ", round(train_time,3)
    print "Test time: ", round(test_time,3)
    
    #Visualization
    mytools.prettyPicture(clf, X_test, y_test)
    plt.show()
Exemplo n.º 2
0
    
    y = [round(bumpiness[i]*grade[i]+0.3+0.1) for i in xrange(0,n_points)]
    for i in xrange(0,n_points):
        if grade[i] > 0.8 and bumpiness[i]>0.8:
            y[i] = 1.0
    #print y
    #split to test and train
    X = [[gg, bb] for gg,bb in zip(grade, bumpiness)]
    split = int(0.75*n_points)
    X_train = X[0:split]
    X_test = X[split:]
    y_train = y[0:split]
    y_test = y[split:]
    return X_train, X_test, y_train, y_test

X_train, X_test, y_train, y_test = mytools.make_fake_data()
#scatter plot
xx=[]
yy=[]
colors=[]
for idx, point in enumerate(X):
    xx.append(point[0])
    yy.append(point[1])
    if y[idx] == 1:
        colors.append('blue') #fase
    else:
        colors.append("yellow")
plt.figure(0)
plt.title("Training data")
plt.xlabel('grade')
plt.ylabel('bumpiness')