|
5 | 5 | from nnlearn.network import FFNN, DenseLayer
|
6 | 6 | from nnlearn.datasets import load_iris
|
7 | 7 | from nnlearn.metrics import accuracy_score
|
| 8 | +from nnlearn.util import ScriptInformation |
8 | 9 |
|
9 | 10 | # TODO: replace this with own implentation
|
10 | 11 | from sklearn import preprocessing
|
11 | 12 | from sklearn.model_selection import train_test_split
|
12 | 13 |
|
13 | 14 |
|
14 | 15 | def test_ffnn_classifier():
|
15 |
| - |
16 |
| - # Load and split data |
| 16 | + |
| 17 | + logger = ScriptInformation() |
| 18 | + logger.section_start(":herb: FFNN - IRIS") |
| 19 | + logger.script_time() |
| 20 | + logger.author("Ludek", "Cizinsky") |
| 21 | + logger.section_start(":construction: Prepare input for the model") |
| 22 | + |
| 23 | + logger.working_on("Load and split data") |
17 | 24 | X, y = load_iris()
|
18 | 25 |
|
19 |
| - # Process the data |
| 26 | + logger.working_on("Process the data") |
20 | 27 | y = preprocessing.LabelEncoder().fit_transform(y)
|
21 | 28 | X = preprocessing.StandardScaler().fit_transform(X)
|
22 | 29 |
|
23 |
| - # Train test split |
| 30 | + logger.working_on("Train test split") |
24 | 31 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
|
25 | 32 | m = X_train.shape[1]
|
26 |
| - |
27 |
| - # Define the layers |
| 33 | + |
| 34 | + logger.working_on("Define the layers") |
28 | 35 | layers = [DenseLayer(m, 3), DenseLayer(3, 4), DenseLayer(4, 3, activation='softmax')]
|
29 | 36 |
|
30 |
| - # Train the model |
| 37 | + logger.section_start(":robot: Train the model") |
31 | 38 | clf = FFNN(layers,
|
32 |
| - epochs = 1, |
| 39 | + logger=logger, |
| 40 | + epochs = 50, |
33 | 41 | loss_func='cross_entropy',
|
34 | 42 | batch_size=.5,
|
35 | 43 | lr=.9,
|
36 | 44 | shuffle=True)
|
37 | 45 | clf.fit(X_train, y_train)
|
| 46 | + |
| 47 | + clf.fig.savefig("training.png", bbox_inches='tight') |
| 48 | + logger.c.print(clf.report) |
38 | 49 |
|
39 |
| - # Validate the model |
| 50 | + logger.section_start(":crystal_ball: Validate the model") |
40 | 51 | y_hat = clf.predict(X_test)
|
41 |
| - print(f'Validation accuracy: {accuracy_score(y_test, y_hat)}') |
| 52 | + acc = accuracy_score(y_test, y_hat) |
| 53 | + logger.important_metric('Accuracy', acc) |
42 | 54 |
|
| 55 | + logger.save("ffnn-iris.html") |
43 | 56 |
|
44 | 57 | if __name__ == '__main__':
|
45 | 58 | test_ffnn_classifier()
|
|
0 commit comments