Esempio n. 1
0
def schedule_B(gamma_0, t):
    return gamma_0 / (1 + t)


# schedule A
print('SVM primal sgd with schedule A')
for C in C_vals:
    w = SVM.SVM_primal_sgd(X_train,
                           y_train,
                           epochs=100,
                           C=C,
                           gamma=0.01,
                           schedule_func=schedule_A)
    print('C:', C, 'weights:', w)
    err_train = SVM.SVM_primal_test(X_train, y_train, w)
    err_test = SVM.SVM_primal_test(X_test, y_test, w)
    print('training error:', err_train, 'test error', err_test)

# schedule B
print('\nSVM primal sgd with schedule B')
for C in C_vals:
    w = SVM.SVM_primal_sgd(X_train,
                           y_train,
                           epochs=100,
                           C=C,
                           gamma=0.01,
                           schedule_func=schedule_B)
    print('C:', C, 'weights:', w)
    err_train = SVM.SVM_primal_test(X_train, y_train, w)
    err_test = SVM.SVM_primal_test(X_test, y_test, w)