Пример #1
0
def predict_third_set(gram_train,
                      gram_test,
                      y_label,
                      scale=20000,
                      max_iter=1,
                      lambd=0.00001):

    gram_train = gram_train[0] + gram_train[1] + gram_train[2]
    gram_test = gram_test[0] + gram_test[1] + gram_test[2]

    krl = KRL(gram_m=gram_train / scale, max_iter=max_iter, lambd=lambd)
    krl.fit(np.array(y_label))
    y_pred_krl = krl.predict(gram_test / scale)

    clf = SVM(gram_m=gram_train)
    clf.fit(np.array(y_label))
    y_pred_svm = clf.predict(gram_test)

    y_pred = np.sign(y_pred_svm + y_pred_krl)
    return y_pred
Пример #2
0
print("Predict the EVAL set")
y_preds = nb.predict(data_eval_compact)['y_preds']
make_submission_data(y_preds, 'nb_1214.csv')

# run Perceptron -----------------------
perceptron = Perceptron(r=0.1, margin=0.01, n_epoch=20)
perceptron.fit(data_train)
print("Predict the TEST set")
perceptron.predict(data_test, perceptron.weights[-1])
print("Predict the EVAL set")
y_preds = perceptron.predict(data_eval, perceptron.weights[-1])['y_preds']
make_submission_data(y_preds, 'perceptron.csv')

# run SVM
svm = SVM(r=0.01, c=1, n_epoch=17)
svm.fit(data_train)
print("Predict the TEST set")
svm.predict(data_test, svm.weights[-1])
print("Predict the EVAL set")
y_preds = svm.predict(data_eval, svm.weights[-1])['y_preds']
make_submission_data(y_preds, 'svm.csv')

# run Logistic -----------------------------
logistic = Logistic(r=0.01, sigma=100, n_epoch=10)
logistic.fit(data_train)
print("Predict the TEST set")
logistic.predict(data_test, logistic.weights[-1])
print("Preidict the EVAL set")
y_preds = logistic.predict(data_eval, logistic.weights[-1])['y_preds']
make_submission_data(y_preds, 'logistic.csv')