예제 #1
0
def main():
    X, Y = util.get_mnist()
    Ntrain = len(Y) // 2
    Xtrain, Ytrain = X[:Ntrain], Y[:Ntrain]
    Xtest, Ytest = X[Ntrain:], Y[Ntrain:]

    model = get_model()
    t0 = datetime.now()
    model.fit(Xtrain, Ytrain)
    print("Training time:", (datetime.now() - t0))

    t0 = datetime.now()
    print("Train accuracy:", model.score(Xtrain, Ytrain))
    print("Time to compute train accuracy:", (datetime.now() - t0),
          "Train size:", len(Ytrain))

    t0 = datetime.now()
    print("Test accuracy:", model.score(Xtest, Ytest))
    print("Time to compute test accuracy:", (datetime.now() - t0),
          "Test size:", len(Ytest))

    # Plot the mean of each class
    # for c, g in iteritems(model.gaussians):
    #     plt.imshow(g['mean'].reshape(28, 28))
    #     plt.title(c)
    #     plt.show()

    util.save_model(model, 'model_bayes')
    def test_image_conversion(self):
        # Arrange
        from PIL import Image

        X, y = util.get_mnist(1)

        X = X.astype('float32')
        # image_arr = X[0].reshape(1,-1)

        image_arr = X[0]

        logging.info(f'Shape: {image_arr.shape}')

        # im = Image.fromarray(np.uint8(X[0]))

        measurement_in_pixels = 28

        image_arr = image_arr.reshape(measurement_in_pixels,
                                      measurement_in_pixels)

        logging.info(f'Type: {type(image_arr)}')

        # image_path = os.path.join(config.DATA_FOLDER_PATH, 'sample.PNG')
        # im = Image.open(image_path)
        # image_arr = np.asarray(im)

        logging.info(f'a shape:{image_arr.shape}')

        image = Image.fromarray(np.uint8(image_arr), mode='L')
예제 #3
0
def get_data(limit=None):
    X, Y = util.get_mnist(limit=limit, otherize_digits=[])
    X_train, X_test, Y_train, Y_test = train_test_split(X,
                                                        Y,
                                                        shuffle=True,
                                                        train_size=0.6)

    return X, Y, X_train, X_test, Y_train, Y_test
예제 #4
0
def get_data(limit=None):
    if RUNNING_LOCAL is True:
        from app import util
        X, Y = util.get_mnist(limit=limit, otherize_digits=[])
    else:
        X, Y = get_train(limit)

    X_train, X_test, Y_train, Y_test = train_test_split(
        X, Y, shuffle=shuffle_sample_data, train_size=0.7)

    return X, Y, X_train, X_test, Y_train, Y_test
예제 #5
0
def get_data(limit=None):
    if RUNNING_LOCAL is True:
        from app import util
        X, y = util.get_mnist(limit=limit)
    else:
        X, y = get_train(limit)

    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        shuffle=False,
                                                        train_size=0.7)

    return X, y, X_train, X_test, y_train, y_test
예제 #6
0
def main():
    X, Y = get_mnist()
    Ntrain = len(Y) // 2
    Xtrain, Ytrain = X[:Ntrain], Y[:Ntrain]
    Xtest, Ytest = X[Ntrain:], Y[Ntrain:]

    model = get_model()
    t0 = datetime.now()
    model.fit(Xtrain, Ytrain)
    print("Training time:", (datetime.now() - t0))

    t0 = datetime.now()
    print("Train accuracy:", model.score(Xtrain, Ytrain))
    print("Time to compute train accuracy:", (datetime.now() - t0),
          "Train size:", len(Ytrain))

    t0 = datetime.now()
    print("Test accuracy:", model.score(Xtest, Ytest))
    print("Time to compute test accuracy:", (datetime.now() - t0),
          "Test size:", len(Ytest))