Exemple #1
0
def test_logreg():
    X_train, Y_train, X_test, Y_test = import_census(CENSUS_FILE_PATH)
    num_features = X_train.shape[1]

    # Add a bias
    X_train_b = np.append(X_train, np.ones((len(X_train), 1)), axis=1)
    X_test_b = np.append(X_test, np.ones((len(X_test), 1)), axis=1)

    # my_x=np.array([[3,4],[5,6],[7,8],[9,10],[22,22],[12,23]])

    # my_y=np.array([0,1,2,0,2,1]).reshape(6,)
    # #print(my_y)
    # my_x = np.append(my_x, np.ones((len(my_x), 1)), axis=1)

    # test_model = LogisticRegression(2, 3, 2, CONV_THRESHOLD)
    # #print(test_model.predict(my_x))
    # test_model.train(my_x, my_y)

    ## Logistic Regression ###
    #print(X_train_b.shape)
    #print(Y_train.shape)
    model = LogisticRegression(num_features, NUM_CLASSES, BATCH_SIZE,
                               CONV_THRESHOLD)

    #print(model.loss(X_train_b, Y_train))

    num_epochs = model.train(X_train_b, Y_train)
    acc = model.accuracy(X_test_b, Y_test) * 100
    print("Test Accuracy: {:.1f}%".format(acc))
    print("Number of Epochs: " + str(num_epochs))

    acc = 0

    return acc
Exemple #2
0
def test_logreg():
    X_train, Y_train, X_test, Y_test = import_census(CENSUS_FILE_PATH)
    num_features = X_train.shape[1]

    # Add a bias
    X_train_b = np.append(X_train, np.ones((len(X_train), 1)), axis=1)
    X_test_b = np.append(X_test, np.ones((len(X_test), 1)), axis=1)

    ### Logistic Regression ###
    model = LogisticRegression(num_features, NUM_CLASSES, BATCH_SIZE,
                               CONV_THRESHOLD)
    num_epochs = model.train(X_train_b, Y_train)
    acc = model.accuracy(X_test_b, Y_test) * 100
    print("Test Accuracy: {:.1f}%".format(acc))
    print("Number of Epochs: " + str(num_epochs))

    return acc
Exemple #3
0
def test_logreg():

    X_train, Y_train, X_test, Y_test = import_mnist(MNIST_TRAIN_INPUTS_PATH,
                                                    MNIST_TRAIN_LABELS_PATH,
                                                    MNIST_TEST_INPUTS_PATH,
                                                    MNIST_TEST_LABELS_PATH)
    num_features = X_train.shape[1]

    # Add a bias
    X_train_b = np.append(X_train, np.ones((len(X_train), 1)), axis=1)
    X_test_b = np.append(X_test, np.ones((len(X_test), 1)), axis=1)

    ### Logistic Regression ###
    print('--------- LOGISTIC REGRESSION w/ SGD ---------')
    model = LogisticRegression(num_features, MNIST_CLASSES)
    model.train(X_train_b, Y_train)
    print("Test Accuracy: {:.1f}%".format(
        model.accuracy(X_test_b, Y_test) * 100))