Examples

Some quick examples of how one might implement pre-built models from Nue.

Linear Regression Example

import numpy as np
import pandas as pd

from nue import linreg

data = pd.read_csv('examples/data/linear_regression_dataset2.csv')
data = np.array(data)

''' Pre processing data'''

X_train = data[:, 0:4].T # (3, 500) 
Y_train = data[:, 4].T.reshape(-1, 2000)

X_train_scaled = (X_train - np.min(X_train, axis=0)) / (np.max(X_train, axis=0) - np.min(X_train, axis=0))

''' Running model'''

lr = linreg.LinearRegression(X_train, Y_train, 4, .001, 10000)

w, b = lr.model()

Logistic Regression Example

import numpy as np
import pandas as pd

from nue import logreg as lr

''' Pre processing data'''

data = pd.read_csv('examples/data/randomtrain.csv')
data = np.array(data)

X_train = data[:, :2].T
Y_train = data[:, 2].T.reshape(-1, 200)

print(X_train.shape)
print(Y_train.shape)

''' Running model '''

model = lr.LogisticRegression(X_train, Y_train, 2, .1,  50000)

model.model()

Neural Network Example for MNIST

import numpy as np
import pandas as pd

from nue import nn

''' Pre-processing data '''

data = pd.read_csv('examples/data/mnist_train.csv')
data = np.array(data) # 60000, 785

Y_train = data[:, 0].T.reshape(1, -1)# 1, 60000
X_train = data[:, 1:786].T / 255 # 784, 60000

''' Running model '''

model = nn.NN(X_train, Y_train, 784, 10, 32, .1, 1000)

model.model()