Spaces:
Sleeping
Sleeping
File size: 1,213 Bytes
031ac83 f9522cf 4e6140d 4c97910 88a3c01 4c97910 79f3d28 4c97910 88a3c01 4c97910 79f3d28 ffc3a3a c2ccf60 4c97910 ffc3a3a 79f3d28 ffc3a3a ba1e2db 4c97910 79f3d28 c504867 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
from sklearn.model_selection import train_test_split
import numpy as np
from neural_network.opts import activation
from neural_network.backprop import bp
def init(X: np.array, hidden_size: int) -> dict:
"""
returns a dictionary containing randomly initialized
weights and biases to start off the neural_network
"""
return {
"w1": np.random.randn(X.shape[1], hidden_size),
"b1": np.zeros((1, hidden_size)),
"w2": np.random.randn(hidden_size, 3), # Output layer has 3 neurons
"b2": np.zeros((1, 3)), # Output layer has 3 neurons
}
def main(
X: np.array,
y: np.array,
args,
) -> None:
wb = init(X, args["hidden_size"])
act = activation[args["activation_func"]]
args["activation_func"] = act["main"]
args["func_prime"] = act["prime"]
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
test_size=0.2,
random_state=8675309,
)
model = bp(
X_train=X_train,
y_train=y_train,
wb=wb,
args=args,
)
# evaluate the model and return final results
model.eval(
X_test=X_test,
y_test=y_test,
)
return model.to_dict()
|