Spaces:
Sleeping
Sleeping
Commit
·
662226e
1
Parent(s):
be7edfc
Upload 12 files
Browse files- BackPropogation.py +53 -0
- Perceptron.py +46 -0
- cnn_tumor_model.h5 +3 -0
- gru_movie_model.h5 +3 -0
- iris_backprop_model.pkl +3 -0
- iris_dnn_model.h5 +3 -0
- iris_perceptron_model.pkl +3 -0
- lstm_imdb_model.h5 +3 -0
- mnist_cnn_model.h5 +3 -0
- requirements.txt +4 -0
- sms_sentiment_model.h5 +3 -0
- spammodel.h5 +3 -0
BackPropogation.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from tqdm import tqdm
|
3 |
+
|
4 |
+
|
5 |
+
class BackPropogation:
|
6 |
+
def __init__(self,learning_rate=0.01, epochs=100,activation_function='step'):
|
7 |
+
self.bias = 0
|
8 |
+
self.learning_rate = learning_rate
|
9 |
+
self.max_epochs = epochs
|
10 |
+
self.activation_function = activation_function
|
11 |
+
|
12 |
+
|
13 |
+
def activate(self, x):
|
14 |
+
if self.activation_function == 'step':
|
15 |
+
return 1 if x >= 0 else 0
|
16 |
+
elif self.activation_function == 'sigmoid':
|
17 |
+
return 1 if (1 / (1 + np.exp(-x)))>=0.5 else 0
|
18 |
+
elif self.activation_function == 'relu':
|
19 |
+
return 1 if max(0,x)>=0.5 else 0
|
20 |
+
|
21 |
+
def fit(self, X, y):
|
22 |
+
error_sum=0
|
23 |
+
n_features = X.shape[1]
|
24 |
+
self.weights = np.zeros((n_features))
|
25 |
+
for epoch in tqdm(range(self.max_epochs)):
|
26 |
+
for i in range(len(X)):
|
27 |
+
inputs = X[i]
|
28 |
+
target = y[i]
|
29 |
+
weighted_sum = np.dot(inputs, self.weights) + self.bias
|
30 |
+
prediction = self.activate(weighted_sum)
|
31 |
+
|
32 |
+
# Calculating loss and updating weights.
|
33 |
+
error = target - prediction
|
34 |
+
self.weights += self.learning_rate * error * inputs
|
35 |
+
self.bias += self.learning_rate * error
|
36 |
+
|
37 |
+
print(f"Updated Weights after epoch {epoch} with {self.weights}")
|
38 |
+
print("Training Completed")
|
39 |
+
|
40 |
+
def predict(self, X):
|
41 |
+
predictions = []
|
42 |
+
for i in range(len(X)):
|
43 |
+
inputs = X[i]
|
44 |
+
weighted_sum = np.dot(inputs, self.weights) + self.bias
|
45 |
+
prediction = self.activate(weighted_sum)
|
46 |
+
predictions.append(prediction)
|
47 |
+
return predictions
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
Perceptron.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from tqdm import tqdm
|
3 |
+
|
4 |
+
|
5 |
+
class Perceptron:
|
6 |
+
|
7 |
+
def __init__(self,learning_rate=0.01, epochs=100,activation_function='step'):
|
8 |
+
self.bias = 0
|
9 |
+
self.learning_rate = learning_rate
|
10 |
+
self.max_epochs = epochs
|
11 |
+
self.activation_function = activation_function
|
12 |
+
|
13 |
+
|
14 |
+
def activate(self, x):
|
15 |
+
if self.activation_function == 'step':
|
16 |
+
return 1 if x >= 0 else 0
|
17 |
+
elif self.activation_function == 'sigmoid':
|
18 |
+
return 1 if (1 / (1 + np.exp(-x)))>=0.5 else 0
|
19 |
+
elif self.activation_function == 'relu':
|
20 |
+
return 1 if max(0,x)>=0.5 else 0
|
21 |
+
|
22 |
+
def fit(self, X, y):
|
23 |
+
n_features = X.shape[1]
|
24 |
+
self.weights = np.random.randint(n_features, size=(n_features))
|
25 |
+
for epoch in tqdm(range(self.max_epochs)):
|
26 |
+
for i in range(len(X)):
|
27 |
+
inputs = X[i]
|
28 |
+
target = y[i]
|
29 |
+
weighted_sum = np.dot(inputs, self.weights) + self.bias
|
30 |
+
prediction = self.activate(weighted_sum)
|
31 |
+
print("Training Completed")
|
32 |
+
|
33 |
+
def predict(self, X):
|
34 |
+
predictions = []
|
35 |
+
for i in range(len(X)):
|
36 |
+
inputs = X[i]
|
37 |
+
weighted_sum = np.dot(inputs, self.weights) + self.bias
|
38 |
+
prediction = self.activate(weighted_sum)
|
39 |
+
predictions.append(prediction)
|
40 |
+
return predictions
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
cnn_tumor_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c0f23e5dd30e1b7b5d76fdeb33bdbd3f7b762cd641541ffb99f32e97820bd747
|
3 |
+
size 391811360
|
gru_movie_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2b0fa91a9f80f4388c147f3b4a638fbbb30a6f99834dec25060420fde323afac
|
3 |
+
size 43126776
|
iris_backprop_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3fab088872c073d72e358cb47f7c881045fd816657901ab1cae79d3e0bb98782
|
3 |
+
size 309
|
iris_dnn_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:78da3a8bf14f537b5cc9f117bee53142d8deb556e2ed4d235d76f6735687dc2e
|
3 |
+
size 77096
|
iris_perceptron_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4a008932324739f92bb66a0bac74ee9d09cff37af63cee45ab5bd97853c56c03
|
3 |
+
size 268
|
lstm_imdb_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b03fc488fed00a614e9c9d85b4bfc4c3de4bf51f950ab3fdbc959cc8736f456c
|
3 |
+
size 2594296
|
mnist_cnn_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f155240105c9ff88de0783908008834e4dad493757a0fd0aa2c0d8e3fa5ee19f
|
3 |
+
size 8405920
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
Pillow
|
3 |
+
tensorflow
|
4 |
+
numpy
|
sms_sentiment_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ee684cae96a01d6a7304de0eed0df6ace4b9b354375ad0c81da81f61412bcda8
|
3 |
+
size 1775224
|
spammodel.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:260ffcd8ce899bd9ea90ec4ed7c7d6c04311c8fac596824219736918a1b4782d
|
3 |
+
size 2269016
|