Ejemplo n.º 1
0
def s3vm_moon():
    my_random_generator = random.Random()
    my_random_generator.seed(0)
    # dense moons data set
    X_train_l, L_train_l, X_train_u, X_test, L_test = examples.get_moons_data(
        my_random_generator)
    print("Unique labels: ", np.unique(L_test))
    print("X_train_l: ", X_train_l)
    print("L_train_l: ", L_train_l)
    print("X_train_u: ", X_train_u)
    print("X_test: ", X_test)
    print("L_test: ", L_test)
    t_start = time.time()
    # the parameter estimate_r for the balance ratio has to be provided explicitly, since the estimation
    # is bad due to only 5 labeled patterns in the training set.
    model = QN_S3VM(
        X_train_l,
        L_train_l,
        X_train_u,
        my_random_generator,
        lam=0.0009765625,
        lamU=1,
        kernel_type="RBF",
        sigma=0.5,
        estimate_r=0.0,
    )
    preds_train = model.train()
    t_end = time.time()
    elapsed_time = t_end - t_start
    preds = model.getPredictions(X_test)
    error = examples.classification_error(preds, L_test)
    print("Time needed to compute the model: ", elapsed_time, " seconds")
    print("Classification error of QN-S3VM: ", error)

    X_draw = np.concatenate((X_train_l, X_train_u), axis=0)
    y_draw = np.hstack((L_train_l, np.zeros(len(X_train_u))))
    disp(X_draw, y_draw)
    disp(X_draw, preds_train)
    disp(np.array(X_test), np.array(preds))
    return
Ejemplo n.º 2
0
    # sparse text data set
    X_train_l, L_train_l, X_train_u, X_test, L_test, kw = examples.get_text_data(
        my_random_generator)
    t_start = time.time()
    model = QN_S3VM(X_train_l,
                    L_train_l,
                    X_train_u,
                    my_random_generator,
                    lam=0.00390625,
                    lamU=1)
    model.train()
    t_end = time.time()
    elapsed_time = t_end - t_start
    preds = model.getPredictions(X_test)
    error = examples.classification_error(preds, L_test)
    print("Time needed to compute the model: ", elapsed_time, " seconds")
    print("Classification error of QN-S3VM: ", error)

    # dense gaussian data set
    X_train_l, L_train_l, X_train_u, X_test, L_test = examples.get_gaussian_data(
        my_random_generator)
    t_start = time.time()
    model = QN_S3VM(X_train_l,
                    L_train_l,
                    X_train_u,
                    my_random_generator,
                    lam=1,
                    lamU=1)
    model.train()
    t_end = time.time()
Ejemplo n.º 3
0

if __name__ == "__main__":
    import random, examples, time
    my_random_generator = random.Random()
    my_random_generator.seed(0)

    # sparse text data set
    X_train_l, L_train_l, X_train_u, X_test, L_test, kw = examples.get_text_data(my_random_generator)
    t_start = time.time()
    model = QN_S3VM(X_train_l, L_train_l, X_train_u, my_random_generator, lam=0.00390625, lamU=1)
    model.train()
    t_end = time.time()
    elapsed_time = t_end - t_start
    preds = model.getPredictions(X_test)
    error = examples.classification_error(preds,L_test)
    print "Time needed to compute the model: ", elapsed_time, " seconds"
    print "Classification error of QN-S3VM: ", error

    # dense gaussian data set
    X_train_l, L_train_l, X_train_u, X_test, L_test = examples.get_gaussian_data(my_random_generator)
    t_start = time.time()
    model = QN_S3VM(X_train_l, L_train_l, X_train_u, my_random_generator, lam=1, lamU=1)
    model.train()
    t_end = time.time()
    elapsed_time = t_end - t_start
    preds = model.getPredictions(X_test)
    error = examples.classification_error(preds,L_test)
    print "Time needed to compute the model: ", elapsed_time, " seconds"
    print "Classification error of QN-S3VM: ", error