-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnn_iris.py
More file actions
33 lines (26 loc) · 841 Bytes
/
Copy pathnn_iris.py
File metadata and controls
33 lines (26 loc) · 841 Bytes
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
from src import cnn
import numpy as np
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
iris = load_iris()
X = iris.data
Y = iris.target
Y_onehot = cnn.CNN.one_hot_encode(Y.reshape((-1,1)),num_cats=3)
print(X.shape,Y_onehot.shape)
# print(X,Y_onehot)
model = cnn.CNN(optimiser_method='adam')
model.add_layer(
cnn.CNN.FC_Layer(3,input_shape=(4,1),activation='relu',initiation_method='kaiming_normal')
)
model.add_layer(
cnn.CNN.FC_Layer(3,activation='softmax',initiation_method='kaiming_normal')
)
model.prepare_model()
input()
# print(X[0:1],X[0:1].shape)
# print(Y[0:1],Y[0:1].shape, max(Y[0:1].shape))
model.train(X,Y_onehot,epochs=30,max_batch_size=64,cost_fn='cross_entropy',shuffle=True,learning_rate=0.1)
print(model.history)
# print(model.structure[-1].output)
plt.plot(model.history['cost'])
plt.show()