Exemple #1
0
def task_2_results():
    kf = KFold(n_folds=k)
    accuracies = []
    for train_index, test_index in kf.split(y):
        X_train = X_manual[train_index]
        X_test = X_manual[test_index]
        y_train = y[train_index]
        y_test = y[test_index]
        SVM.learn_svm(X_train, y_train, prefix+"task_2_model")
        accuracies.append(SVM.test_svm_accuracy(X_test, y_test, prefix+"task_2_model"))
    print "Accuracy for task_2:", np.mean(accuracies), "+-", np.std(accuracies)
    return accuracies
Exemple #2
0
def task_3_results():
    kf = KFold(n_folds=k)
    num_manual_features = len(X_manual[0])
    accuracies = []
    for i in range(num_manual_features):
        accuracies.append([])
    X_manual_np = np.asarray(X_manual)
    for train_index, test_index in kf.split(X_content):
        X_train = X_content[train_index]
        X_test = X_content[test_index]
        for i in range(num_manual_features):
            y_train = X_manual_np[train_index, i]
            y_test = X_manual_np[test_index, i]
            SVM.learn_svm(X_train, list(y_train), prefix+"task_3_model")
            accuracies[i].append(SVM.test_svm_accuracy(X_test, list(y_test), prefix+"task_3_model"))

    for i in range(num_manual_features):
        print "Accuracy for task_3 (" + str(names[i]) + "):", np.mean(accuracies[i]), "+-", np.std(accuracies[i])

    return accuracies
Exemple #3
0
def task_4_results():
    kf = KFold(n_folds=k)
    num_manual_features = len(X_manual[0])
    accuracies = []
    X_manual_np = np.asarray(X_manual)
    for train_index, test_index in kf.split(X_content):
        X_content_train = X_content[train_index]
        X_manual_test = X_manual[test_index]  # Just for structure, populated below
        X_content_test = X_content[test_index]
        num_test = len(test_index)
        for i in range(num_manual_features):
            X_np_train = X_manual_np[train_index, i]
            SVM.learn_svm(X_content_train, list(X_np_train), prefix+"task_4_model")
            for j in range(num_test):
                X_manual_test[j][i] = SVM.load_svm(prefix+"task_4_model").predict([X_content_test[j]])[0]
        X_manual_train = X_manual[train_index]
        y_train = y[train_index]
        y_test = y[test_index]
        SVM.learn_svm(X_manual_train, y_train, prefix+"task_4_model_1")
        accuracies.append(SVM.test_svm_accuracy(X_manual_test, y_test, prefix+"task_4_model_1"))

    print "Accuracy for task_4:", np.mean(accuracies), "+-", np.std(accuracies)
    return accuracies