Skip to content

Commit 9fc6ca4

Browse files
committed
ANN models with MLP sklearn
1 parent 47b4d50 commit 9fc6ca4

File tree

60 files changed

+133
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+133
-137
lines changed

.DS_Store

0 Bytes
Binary file not shown.

app.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import numpy as np
2121
import plotly.graph_objs as go
2222
from dash import Input, Output, State, dcc, html
23-
import tensorflow as tf
24-
from tensorflow import keras
25-
from keras.models import load_model
26-
import xgboost
23+
# import tensorflow as tf
24+
# from tensorflow import keras
25+
# from keras.models import load_model
26+
#import xgboost
2727
import re
2828

2929

@@ -462,7 +462,7 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
462462

463463
rmse, rmse_tf = regression_model_info_extractor("Suchey_Brooks_1990")
464464

465-
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0][0],rmse_tf)
465+
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
466466

467467
classification = output_classification(y_classification_sklearn[0], \
468468
y_classification_tf[0])
@@ -479,7 +479,7 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
479479

480480
rmse, rmse_tf = regression_model_info_extractor("Meindl_and_Lovejoy")
481481

482-
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0][0],rmse_tf)
482+
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
483483

484484
classification = output_classification(y_classification_sklearn[0], \
485485
y_classification_tf[0])
@@ -494,7 +494,7 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
494494

495495
rmse, rmse_tf = regression_model_info_extractor("Lovejoy_et_al")
496496

497-
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0][0],rmse_tf)
497+
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
498498

499499
classification = output_classification(y_classification_sklearn[0], \
500500
y_classification_tf[0])
@@ -509,7 +509,7 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
509509

510510
rmse, rmse_tf = regression_model_info_extractor("Buckberry_and_Chamberlain")
511511

512-
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0][0],rmse_tf)
512+
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
513513

514514
classification = output_classification(y_classification_sklearn[0], \
515515
y_classification_tf[0])
@@ -525,7 +525,7 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
525525

526526
rmse, rmse_tf = regression_model_info_extractor("Suchey_Brooks_1990_and_Lovejoy_et_al")
527527

528-
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0][0],rmse_tf)
528+
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
529529

530530
classification = output_classification(y_classification_sklearn[0], \
531531
y_classification_tf[0])
@@ -541,7 +541,7 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
541541

542542
rmse, rmse_tf = regression_model_info_extractor("Suchey_Brooks_1990_and_Buckberry_Chamberlain")
543543

544-
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0][0],rmse_tf)
544+
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
545545

546546
classification = output_classification(y_classification_sklearn[0], \
547547
y_classification_tf[0])
@@ -560,7 +560,7 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
560560

561561
rmse, rmse_tf = regression_model_info_extractor("All")
562562

563-
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0][0],rmse_tf)
563+
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
564564

565565
classification = output_classification(y_classification_sklearn[0], \
566566
y_classification_tf[0])
@@ -573,11 +573,11 @@ def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_click
573573
def output_classification(y_sklearn, y_tf):
574574

575575
text = (
576-
f"The sample is split into three age-groups, "
577-
f"14-34 (class 0), 35-49 (class 1), and 50- (class 2). "
578-
f"Using the sklearn library's classification algorithms we predict that "
579-
f"for the given input the sample belongs to the {y_sklearn} class, "
580-
f"and using a tensorflow neural network the prediction for the class is {y_tf}."
576+
f"The sample was divided into three age groups: "
577+
f"14-34 (class 0), 35-49 (class 1), and 50+ (class 2). "
578+
f"Utilizing classification algorithms from the sklearn library we predict "
579+
f"that the given input belongs to class {y_sklearn}. "
580+
f"Additionally, our neural network predicts that the input belongs to class {y_tf}."
581581
)
582582

583583
card = dbc.Card(
@@ -599,12 +599,12 @@ def output_classification(y_sklearn, y_tf):
599599
def output_regression(result_sklearn, rmse_sklearn, result_tf, rmse_tf):
600600

601601
text = (
602-
f"Using regression, we can make a prediction for the age directly. "
603-
f"Using the sklearn library's regression algorithms we predict an age of {result_sklearn:.1f}"
602+
f"We can make a direct prediction for age using regression. "
603+
f"With the help of regression algorithms from the sklearn library, we predict an age of {result_sklearn:.1f}"
604604
f"\u00B1"
605605
f"{rmse_sklearn:.1f}"
606-
f", and "
607-
f"using a tensorflow neural network we predict {result_tf:.1f}"
606+
f". "
607+
f"Additionally, our neural network predicts an age of {result_tf:.1f}"
608608
f"\u00B1"
609609
f"{rmse_tf:.1f}"
610610
)
@@ -630,20 +630,26 @@ def calculate_y_vectors(model, X):
630630
pickle.load(
631631
open("".join(["./models/classification_right_",model,".dat"]), "rb"))
632632
classification_model_tf = \
633-
load_model(
634-
"".join(["./models/ann_classification_right_",model,".h5"]))
633+
pickle.load(
634+
open("".join(["./models/ann_classification_right_",model,".dat"]), "rb"))
635+
636+
637+
# load_model(
638+
# "".join(["./models/ann_classification_right_",model,".h5"]))
635639

636640
regression_model_sklearn = \
637641
pickle.load(
638642
open("".join(["./models/regression_right_",model,".dat"]), "rb"))
639643
regression_model_tf = \
640-
load_model(
641-
"".join(["./models/ann_regression_right_",model,".h5"]))
644+
pickle.load(
645+
open("".join(["./models/ann_regression_right_",model,".dat"]), "rb"))
646+
# load_model(
647+
# "".join(["./models/ann_regression_right_",model,".h5"]))
642648

643649
y_classification_sklearn = classification_model_sklearn.predict(X)
644650

645651
y_classification_tf = classification_model_tf.predict(X)
646-
y_classification_tf = np.argmax(y_classification_tf, axis=1)
652+
#y_classification_tf = np.argmax(y_classification_tf, axis=1)
647653

648654
y_regression_sklearn = regression_model_sklearn.predict(X)
649655
y_regression_tf = regression_model_tf.predict(X)
41.3 KB
Binary file not shown.
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
---------------------------------
22
All
33
Dataset size: 140 140
4-
Accuracy: 0.6857142857142857
4+
Best classifier: {'learner': MLPClassifier(activation='tanh', alpha=0.004441038058541382,
5+
beta_1=0.9527358121951149, beta_2=0.9799242066519736,
6+
epsilon=9.89535978544575e-06, learning_rate='adaptive',
7+
learning_rate_init=0.030775305216924835, max_fun=25541,
8+
max_iter=273, momentum=0.9565810529873298, n_iter_no_change=20,
9+
power_t=0.39730012597415304, random_state=4, solver='sgd',
10+
tol=0.006128519233101691,
11+
validation_fraction=0.18358166633762218), 'preprocs': (StandardScaler(with_std=False),), 'ex_preprocs': ()}
12+
Accuracy: 0.7142857142857143
513
Confusion matrix:
6-
[[ 5 2 0]
14+
[[ 6 1 0]
715
[ 2 0 5]
816
[ 0 2 19]]
9-
LOOCV accuracy: 0.7642857142857143
17+
20-fold accuracy: 0.7142857142857142
Binary file not shown.
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
---------------------------------
22
Buckberry and Chamberlain
33
Dataset size: 140 140
4-
Accuracy: 0.7428571428571429
4+
Best classifier: {'learner': MLPClassifier(alpha=0.0013798362489681195, beta_1=0.8427429717332454,
5+
beta_2=0.9793499837952889, epsilon=6.782183444500067e-06,
6+
hidden_layer_sizes=(20,), learning_rate='invscaling',
7+
learning_rate_init=0.05362664460304082, max_fun=13641,
8+
max_iter=259, momentum=0.9253775432649511, n_iter_no_change=30,
9+
power_t=0.6932640248738308, random_state=0,
10+
tol=0.00146402570692232, validation_fraction=0.07467194239359302), 'preprocs': (PCA(n_components=5),), 'ex_preprocs': ()}
11+
Accuracy: 0.7142857142857143
512
Confusion matrix:
6-
[[ 4 0 3]
7-
[ 0 1 6]
8-
[ 0 0 21]]
9-
LOOCV accuracy: 0.6928571428571428
13+
[[ 5 1 1]
14+
[ 2 0 5]
15+
[ 0 1 20]]
16+
20-fold accuracy: 0.6785714285714286
Binary file not shown.
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
---------------------------------
22
Lovejoy et al
33
Dataset size: 140 140
4-
Accuracy: 0.8
4+
Best classifier: {'learner': MLPClassifier(activation='identity', alpha=0.007888821884740403,
5+
beta_1=0.9037988007792519, beta_2=0.9739918146106623,
6+
epsilon=1.233568968982738e-06,
7+
learning_rate_init=0.09178142853860238, max_fun=29535,
8+
max_iter=270, momentum=0.9859029509207262, n_iter_no_change=20,
9+
power_t=0.7946478078411516, random_state=3,
10+
tol=0.009186083269769324,
11+
validation_fraction=0.02832480065184169), 'preprocs': (MinMaxScaler(clip=True, feature_range=(0.0, 1.0)),), 'ex_preprocs': ()}
12+
Accuracy: 0.8285714285714286
513
Confusion matrix:
614
[[ 7 0 0]
7-
[ 1 0 6]
15+
[ 1 1 5]
816
[ 0 0 21]]
9-
LOOCV accuracy: 0.7785714285714286
17+
20-fold accuracy: 0.7999999999999999
Binary file not shown.
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
---------------------------------
22
Meindl and Lovejoy
33
Dataset size: 140 140
4-
Accuracy: 0.5428571428571428
4+
Best classifier: {'learner': MLPClassifier(activation='identity', alpha=0.0017893961349955139,
5+
beta_1=0.8120661393066152, beta_2=0.9848215178951898,
6+
epsilon=7.466114747734495e-06, hidden_layer_sizes=(10, 10),
7+
learning_rate_init=0.048556142949039094, max_fun=20396,
8+
max_iter=254, momentum=0.8455372036522589, n_iter_no_change=30,
9+
power_t=0.7796736921110702, random_state=1, solver='sgd',
10+
tol=0.007026905109325465,
11+
validation_fraction=0.15163797733143308), 'preprocs': (StandardScaler(with_mean=False, with_std=False),), 'ex_preprocs': ()}
12+
Accuracy: 0.6
513
Confusion matrix:
614
[[ 5 2 0]
715
[ 0 1 6]
8-
[ 3 5 13]]
9-
LOOCV accuracy: 0.6571428571428571
16+
[ 3 3 15]]
17+
20-fold accuracy: 0.6428571428571428

0 commit comments

Comments
 (0)