Spaces:
Sleeping
Sleeping
Commit
·
3563daa
1
Parent(s):
f9846ff
successfully returning data on how the neural network performed
Browse files- app.py +1 -2
- neural_network/neural_network.py +9 -6
app.py
CHANGED
@@ -28,7 +28,6 @@ def not_valid(params: dict):
|
|
28 |
@app.route("/", methods=["GET"])
|
29 |
def index():
|
30 |
params = request.json
|
31 |
-
print(params)
|
32 |
error_message = not_valid(params=params)
|
33 |
if error_message:
|
34 |
return make_response(error_message, 400)
|
@@ -44,7 +43,7 @@ def index():
|
|
44 |
return jsonify(model)
|
45 |
|
46 |
|
47 |
-
if __name__ ==
|
48 |
app.run(
|
49 |
debug=True,
|
50 |
)
|
|
|
28 |
@app.route("/", methods=["GET"])
|
29 |
def index():
|
30 |
params = request.json
|
|
|
31 |
error_message = not_valid(params=params)
|
32 |
if error_message:
|
33 |
return make_response(error_message, 400)
|
|
|
43 |
return jsonify(model)
|
44 |
|
45 |
|
46 |
+
if __name__ == "__main__":
|
47 |
app.run(
|
48 |
debug=True,
|
49 |
)
|
neural_network/neural_network.py
CHANGED
@@ -25,6 +25,7 @@ class NeuralNetwork:
|
|
25 |
return self.compute_node(n1, self.w2, self.b2, self.activation_func)
|
26 |
|
27 |
def set_loss_hist(self, loss_hist: list) -> None:
|
|
|
28 |
self.loss_history = loss_hist
|
29 |
|
30 |
def eval(self, X_test, y_test) -> None:
|
@@ -35,18 +36,20 @@ class NeuralNetwork:
|
|
35 |
return func(np.dot(arr, w) + b)
|
36 |
|
37 |
@classmethod
|
38 |
-
def from_dict(cls, dct):
|
39 |
return cls(**dct)
|
40 |
|
41 |
-
def to_dict(self) -> dict:
|
42 |
return {
|
43 |
-
"w1":
|
44 |
-
"w2":
|
45 |
-
"b1":
|
46 |
-
"b2":
|
47 |
"epochs": self.epochs,
|
48 |
"learning_rate": self.learning_rate,
|
49 |
"activation_func": self.activation_func.__name__,
|
50 |
"func_prime": self.func_prime.__name__,
|
51 |
"hidden_size": self.hidden_size,
|
|
|
|
|
52 |
}
|
|
|
25 |
return self.compute_node(n1, self.w2, self.b2, self.activation_func)
|
26 |
|
27 |
def set_loss_hist(self, loss_hist: list) -> None:
|
28 |
+
assert (isinstance(loss_hist, list))
|
29 |
self.loss_history = loss_hist
|
30 |
|
31 |
def eval(self, X_test, y_test) -> None:
|
|
|
36 |
return func(np.dot(arr, w) + b)
|
37 |
|
38 |
@classmethod
|
39 |
+
def from_dict(cls, dct) -> "NeuralNetwork":
|
40 |
return cls(**dct)
|
41 |
|
42 |
+
def to_dict(self) -> dict[str, list | int | float | str]:
|
43 |
return {
|
44 |
+
"w1": self.w1.tolist(),
|
45 |
+
"w2": self.w2.tolist(),
|
46 |
+
"b1": self.b1.tolist(),
|
47 |
+
"b2": self.b2.tolist(),
|
48 |
"epochs": self.epochs,
|
49 |
"learning_rate": self.learning_rate,
|
50 |
"activation_func": self.activation_func.__name__,
|
51 |
"func_prime": self.func_prime.__name__,
|
52 |
"hidden_size": self.hidden_size,
|
53 |
+
"mse": self.mse,
|
54 |
+
"loss_history": self.loss_history,
|
55 |
}
|