Beispiel #1
0
def Percep(training_data, testing_data, f, coef_init, intercept_init):
    ppn = Perceptron(warm_start=True)
    ppn.fit(training_data, training_label)
    ppn._allocate_parameter_mem(n_classes=3,
                                n_features=f,
                                coef_init=coef_init,
                                intercept_init=intercept_init)
    ppn.fit(training_data, training_label)
    weight = np.c_[(ppn.coef_), (ppn.intercept_).T]
    acc_tra = ppn.score(training_data, training_label)
    acc_tes = ppn.score(testing_data, testing_label)
    result = (weight, acc_tra, acc_tes)
    return result
Beispiel #2
0
#         max_weight = np.concatenate((clf.intercept_.reshape(3, 1), clf.coef_), axis=1)
#     print('\n')
#     print("classification accuracy")
#     print(max_number)
#     print('\n')
#     print("the final 3 weight vectors")
#     print(max_weight)
#     print('\n')

#13 features testing set
max_number = 0
max_weight = [[], [], []]
for i in range(100):
    clf = Perceptron()
    clf._allocate_parameter_mem(n_classes=3,
                                n_features=2,
                                coef_init=np.random.randn(3, 2),
                                intercept_init=np.random.randn(3, ))
    clf.fit(train_std, l2)
    acc = clf.score(test_train_std, test_l2)
    if acc > max_number:
        max_number = acc
        max_weight = np.concatenate((clf.intercept_.reshape(3, 1), clf.coef_),
                                    axis=1)
    print('\n')
    print("classification accuracy")
    print(max_number)
    print('\n')
    print("the final 3 weight vectors")
    print(max_weight)
    print('\n')