Пример #1
0
# only needed for 2-d contour plotting 
x1 = demoData['x1']          # x for class 1 (with label -1)
x2 = demoData['x2']          # x for class 2 (with label +1)     
t1 = demoData['t1']          # y for class 1 (with label -1)
t2 = demoData['t2']          # y for class 2 (with label +1)
p1 = demoData['p1']          # prior for class 1 (with label -1)
p2 = demoData['p2']          # prior for class 2 (with label +1)




#----------------------------------------------------------------------
# First example -> state default values
#----------------------------------------------------------------------
print 'Basic Example - Data'
model = pyGPs.GPC()          # binary classification (default inference method: EP)
model.plotData_2d(x1,x2,t1,t2,p1,p2)
model.getPosterior(x, y)     # fit default model (mean zero & rbf kernel) with data
model.optimize(x, y)         # optimize hyperparamters (default optimizer: single run minimize)
model.predict(z)             # predict test cases

print 'Basic Example - Prediction'
model.plot(x1,x2,t1,t2)

#----------------------------------------------------------------------
# GP classification example
#----------------------------------------------------------------------
print 'More Advanced Example'
# Start from a new model 
model = pyGPs.GPC()    
Пример #2
0
    else:
        y[i, 0] = -1
y = np.int8(y)

#----------------------------------------------------------------------
# Cross Validation
#----------------------------------------------------------------------
K = 10  # number of fold
ACC = []  # accuracy
RMSE = []  # root-mean-square error

cv_run = 0
for x_train, x_test, y_train, y_test in valid.k_fold_validation(x, y, K):
    print 'Run:', cv_run
    # This is a binary classification problem
    model = pyGPs.GPC()
    # Since no prior knowldege, leave everything default
    model.optimize(x_train, y_train)
    # Predit
    ymu, ys2, fmu, fs2, lp = model.predict(x_test, ys=y_test)

    # ymu for classification is a continuous value over -1 to +1
    # If you want predicting result to either one of the classes, take a sign of ymu.
    ymu_class = np.sign(ymu)

    # Evluation
    acc = valid.ACC(ymu_class, y_test)
    print '   accuracy =', round(acc, 2)
    rmse = valid.RMSE(ymu_class, y_test)
    print '   rmse =', round(rmse, 2)
    ACC.append(acc)