Spaces:
Build error
Build error
Commit
·
f9522cf
1
Parent(s):
4c97910
just focusing on neural_network first
Browse files- README.md +2 -0
- main.py +11 -9
- neural_network/backprop.py +2 -6
- neural_network/forwardprop.py +2 -1
- neural_network/main.py +20 -7
- neural_network/opts.py +14 -0
- opts.py +0 -0
README.md
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
# Data-Mining-Study
|
| 2 |
Building out things I have learned in CIS-335 in order to prepare for final exam
|
|
|
|
|
|
|
|
|
| 1 |
# Data-Mining-Study
|
| 2 |
Building out things I have learned in CIS-335 in order to prepare for final exam
|
| 3 |
+
|
| 4 |
+
Trying my best to build most of this stuff purely off of my notes and lecture powerpoints
|
main.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import numpy as np
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def random_dataset():
|
| 5 |
"""
|
|
@@ -14,18 +16,18 @@ def random_dataset():
|
|
| 14 |
)
|
| 15 |
|
| 16 |
|
| 17 |
-
def main(method: str, X: np.array, y: np.array):
|
| 18 |
-
pass
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
if __name__ == "__main__":
|
| 23 |
method = input("\nChoose a method to test: ").lower()
|
|
|
|
|
|
|
| 24 |
|
| 25 |
X, y = random_dataset()
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
X=X,
|
| 29 |
y=y,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
-
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
+
import neural_network.main as nn
|
| 4 |
+
|
| 5 |
|
| 6 |
def random_dataset():
|
| 7 |
"""
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
if __name__ == "__main__":
|
| 20 |
method = input("\nChoose a method to test: ").lower()
|
| 21 |
+
if method != "nn":
|
| 22 |
+
raise ValueError(f"Invalid method '{method}'. Choose 'nn' instead.")
|
| 23 |
|
| 24 |
X, y = random_dataset()
|
| 25 |
+
args = nn.get_args()
|
| 26 |
+
nn.main(
|
| 27 |
+
X=X,
|
| 28 |
y=y,
|
| 29 |
+
epochs=args["epochs"],
|
| 30 |
+
hidden_size=args["hidden_size"],
|
| 31 |
+
learning_rate=args["learning_rate"],
|
| 32 |
+
activation_func=args["activation_func"],
|
| 33 |
)
|
|
|
neural_network/backprop.py
CHANGED
|
@@ -1,11 +1,7 @@
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
-
# for testing only
|
| 7 |
-
if __name__ == "__main__":
|
| 8 |
-
def test():
|
| 9 |
-
pass
|
| 10 |
-
|
| 11 |
-
test()
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
|
| 4 |
+
def bp():
|
| 5 |
+
return
|
| 6 |
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
neural_network/forwardprop.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
|
|
| 1 |
|
| 2 |
|
| 3 |
-
def
|
| 4 |
return
|
| 5 |
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
|
| 3 |
|
| 4 |
+
def fp():
|
| 5 |
return
|
| 6 |
|
neural_network/main.py
CHANGED
|
@@ -1,6 +1,21 @@
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
from neural_network.forwardprop import fp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def init(X: np.array, y: np.array, hidden_size: int) -> dict:
|
|
@@ -17,14 +32,14 @@ def init(X: np.array, y: np.array, hidden_size: int) -> dict:
|
|
| 17 |
|
| 18 |
|
| 19 |
def main(
|
| 20 |
-
X: np.array,
|
| 21 |
-
y: np.array,
|
| 22 |
-
epochs: int,
|
| 23 |
-
hidden_size: int,
|
| 24 |
learning_rate: float,
|
| 25 |
activation_func: str,
|
| 26 |
) -> None:
|
| 27 |
-
wb = init(X, y, hidden_size)
|
| 28 |
|
| 29 |
for e in range(epochs):
|
| 30 |
|
|
@@ -32,5 +47,3 @@ def main(
|
|
| 32 |
bp()
|
| 33 |
|
| 34 |
# update weights and biases
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
from neural_network.forwardprop import fp
|
| 4 |
+
from neural_network.backprop import bp
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def get_args():
|
| 8 |
+
"""
|
| 9 |
+
returns a dictionary containing
|
| 10 |
+
the arguments to be passed to
|
| 11 |
+
the main function
|
| 12 |
+
"""
|
| 13 |
+
return {
|
| 14 |
+
"epochs": int(input("Enter the number of epochs: ")),
|
| 15 |
+
"hidden_size": int(input("Enter the number of hidden nodes: ")),
|
| 16 |
+
"learning_rate": float(input("Enter the learning rate: ")),
|
| 17 |
+
"activation_func": input("Enter the activation function: "),
|
| 18 |
+
}
|
| 19 |
|
| 20 |
|
| 21 |
def init(X: np.array, y: np.array, hidden_size: int) -> dict:
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def main(
|
| 35 |
+
X: np.array,
|
| 36 |
+
y: np.array,
|
| 37 |
+
epochs: int,
|
| 38 |
+
hidden_size: int,
|
| 39 |
learning_rate: float,
|
| 40 |
activation_func: str,
|
| 41 |
) -> None:
|
| 42 |
+
wb = init(X, y, hidden_size)
|
| 43 |
|
| 44 |
for e in range(epochs):
|
| 45 |
|
|
|
|
| 47 |
bp()
|
| 48 |
|
| 49 |
# update weights and biases
|
|
|
|
|
|
neural_network/opts.py
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from neural_network.activation import *
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
activation = {
|
| 5 |
+
"relu": {
|
| 6 |
+
"main": relu,
|
| 7 |
+
"prime": relu_prime,
|
| 8 |
+
},
|
| 9 |
+
|
| 10 |
+
"sigmoid": {
|
| 11 |
+
"main": sigmoid,
|
| 12 |
+
"prime": sigmoid_prime,
|
| 13 |
+
},
|
| 14 |
+
}
|
opts.py
DELETED
|
File without changes
|