Open In Colab

Subclassing for GCE

[1]:
!git clone https://github.com/Jectrianama/GCCE_TEST.git
Cloning into 'GCCE_TEST'...
remote: Enumerating objects: 700, done.
remote: Counting objects: 100% (293/293), done.
remote: Compressing objects: 100% (166/166), done.
remote: Total 700 (delta 159), reused 215 (delta 122), pack-reused 407
Receiving objects: 100% (700/700), 31.57 MiB | 15.55 MiB/s, done.
Resolving deltas: 100% (327/327), done.
[2]:
from sklearn.preprocessing import LabelBinarizer
from sklearn.preprocessing import OneHotEncoder
from scipy.stats import mode
import numpy as np

def ook(t):
  lb = LabelBinarizer()
  y_ook = lb.fit_transform(t)

  if len(np.unique(t))==2:
    y_ook = np.concatenate((1-y_ook.astype(bool), y_ook), axis = 1)

  return y_ook
[3]:
#cargar datos desde drive otros dataset
FILEID = "1AU8pTtCLihBjCZjWITaAzpnEuL4RO436"
#https://drive.google.com/file/d/1AU8pTtCLihBjCZjWITaAzpnEuL4RO436/view?usp=sharing
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id='$FILEID -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id="$FILEID -O  DataGCCE.zip && rm -rf /tmp/cookies.txt
!unzip -o DataGCCE.zip
!dir
--2023-02-11 06:09:55--  https://docs.google.com/uc?export=download&confirm=&id=1AU8pTtCLihBjCZjWITaAzpnEuL4RO436
Resolving docs.google.com (docs.google.com)... 142.251.16.101, 142.251.16.138, 142.251.16.100, ...
Connecting to docs.google.com (docs.google.com)|142.251.16.101|:443... connected.
HTTP request sent, awaiting response... 303 See Other
Location: https://doc-00-90-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/oe6qu1bmg5c2mt9hqh5dvqv90q0isqmo/1676095725000/07591141114418430227/*/1AU8pTtCLihBjCZjWITaAzpnEuL4RO436?e=download&uuid=73e75e53-5ccd-4fa0-a58f-703955a7a0bd [following]
Warning: wildcards not supported in HTTP.
--2023-02-11 06:09:55--  https://doc-00-90-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/oe6qu1bmg5c2mt9hqh5dvqv90q0isqmo/1676095725000/07591141114418430227/*/1AU8pTtCLihBjCZjWITaAzpnEuL4RO436?e=download&uuid=73e75e53-5ccd-4fa0-a58f-703955a7a0bd
Resolving doc-00-90-docs.googleusercontent.com (doc-00-90-docs.googleusercontent.com)... 142.250.31.132, 2607:f8b0:4004:c0b::84
Connecting to doc-00-90-docs.googleusercontent.com (doc-00-90-docs.googleusercontent.com)|142.250.31.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 38377 (37K) [application/x-zip-compressed]
Saving to: ‘DataGCCE.zip’

DataGCCE.zip        100%[===================>]  37.48K  --.-KB/s    in 0s

2023-02-11 06:09:55 (94.3 MB/s) - ‘DataGCCE.zip’ saved [38377/38377]

Archive:  DataGCCE.zip
  inflating: new-thyroid.csv
  inflating: tic-tac-toe-endgame.csv
  inflating: balance-scale.csv
  inflating: file.csv
balance-scale.csv  file.csv   new-thyroid.csv  tic-tac-toe-endgame.csv
DataGCCE.zip       GCCE_TEST  sample_data

Load Data

[4]:
#cargar datos desde drive acceso libre
FILEID = "1SQnWXGROG2Xexs5vn3twuv7SqiWG5njW"
#https://drive.google.com/file/d/1SQnWXGROG2Xexs5vn3twuv7SqiWG5njW/view?usp=sharing
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id='$FILEID -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id="$FILEID -O MADatasets.zip && rm -rf /tmp/cookies.txt
!unzip -o MADatasets.zip
!dir
--2023-02-11 06:09:56--  https://docs.google.com/uc?export=download&confirm=t&id=1SQnWXGROG2Xexs5vn3twuv7SqiWG5njW
Resolving docs.google.com (docs.google.com)... 142.251.16.101, 142.251.16.138, 142.251.16.100, ...
Connecting to docs.google.com (docs.google.com)|142.251.16.101|:443... connected.
HTTP request sent, awaiting response... 303 See Other
Location: https://doc-00-90-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/0b7g49rmhicknmqibjidarh28e3atbh6/1676095725000/07591141114418430227/*/1SQnWXGROG2Xexs5vn3twuv7SqiWG5njW?e=download&uuid=f343be4a-a430-422b-83b0-c80d595af3f2 [following]
Warning: wildcards not supported in HTTP.
--2023-02-11 06:09:56--  https://doc-00-90-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/0b7g49rmhicknmqibjidarh28e3atbh6/1676095725000/07591141114418430227/*/1SQnWXGROG2Xexs5vn3twuv7SqiWG5njW?e=download&uuid=f343be4a-a430-422b-83b0-c80d595af3f2
Resolving doc-00-90-docs.googleusercontent.com (doc-00-90-docs.googleusercontent.com)... 142.250.31.132, 2607:f8b0:4004:c0b::84
Connecting to doc-00-90-docs.googleusercontent.com (doc-00-90-docs.googleusercontent.com)|142.250.31.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 156530728 (149M) [application/zip]
Saving to: ‘MADatasets.zip’

MADatasets.zip      100%[===================>] 149.28M   104MB/s    in 1.4s

2023-02-11 06:09:57 (104 MB/s) - ‘MADatasets.zip’ saved [156530728/156530728]

Archive:  MADatasets.zip
  inflating: MADatasets/util.py
  inflating: MADatasets/Iris1.mat
  inflating: MADatasets/Integra_Labels.mat
  inflating: MADatasets/MAGenerationClassification.py
  inflating: MADatasets/Voice.mat
  inflating: MADatasets/Iris.mat
  inflating: MADatasets/Sinthetic.mat
  inflating: MADatasets/MAGenerationClassification_1.py
  inflating: MADatasets/Bupa1.mat
  inflating: MADatasets/TicTacToe1.mat
  inflating: MADatasets/Wine.mat
  inflating: MADatasets/Breast1.mat
  inflating: MADatasets/Breast.mat
  inflating: MADatasets/Music.mat
  inflating: MADatasets/Pima.mat
  inflating: MADatasets/Ionosphere.mat
  inflating: MADatasets/TicTacToe.mat
  inflating: MADatasets/VoiceData.m
  inflating: MADatasets/util_1.py
  inflating: MADatasets/Ionosphere1.mat
  inflating: MADatasets/__pycache__/util_1.cpython-37.pyc
  inflating: MADatasets/Bupa.mat
  inflating: MADatasets/Wine1.mat
  inflating: MADatasets/__pycache__/util.cpython-37.pyc
  inflating: MADatasets/Pima1.mat
  inflating: MADatasets/Segmentation1.mat
  inflating: MADatasets/Western.mat
  inflating: MADatasets/Integra_Preprocesamiento_Seg_Caracterizacion_time_frec.mat
  inflating: MADatasets/Western1.mat
  inflating: MADatasets/Segmentation.mat
  inflating: MADatasets/Skin_NonSkin.mat
  inflating: MADatasets/Skin_NonSkin1.mat
  inflating: MADatasets/Occupancy1.mat
  inflating: MADatasets/Polarity.mat
  inflating: MADatasets/Occupancy.mat
balance-scale.csv  GCCE_TEST       new-thyroid.csv
DataGCCE.zip       MADatasets      sample_data
file.csv           MADatasets.zip  tic-tac-toe-endgame.csv
[5]:
#load data
import scipy.io as sio
import matplotlib.pyplot as plt
import pandas as pd
import tensorflow as tf #importar tensorflow
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
from sklearn.preprocessing import StandardScaler,MinMaxScaler
import numpy as np
database = 'Ocupancy'#['bupa1', 'breast-cancer-wisconsin1','pima-indians-diabetes1', 'ionosphere1', 'tic-tac-toe1', 'iris1', 'wine1', 'segmentation1']


import pandas as pd
from sklearn.preprocessing import LabelEncoder

dfo= pd.read_csv(r'/content//file.csv')
dfo

#Removing the HumidityRatio attribute which is least correlated to the target attribute
t=dfo['Occupancy'].values
X = dfo.drop(['HumidityRatio','Occupancy'], axis = 1).values

t=t+1
[6]:
import os
os.chdir('/content/GCCE_TEST/Models')
from  keras_ma_gcce import *
from labels_generation import MA_Clas_Gen

Labels Generation

[7]:
Y, iAnn, Lam_r = MA_Clas_Gen(X ,t, R=5, NrP=1)
/usr/local/lib/python3.8/dist-packages/sklearn/manifold/_t_sne.py:780: FutureWarning: The default initialization in TSNE will change from 'random' to 'pca' in 1.2.
  warnings.warn(
/usr/local/lib/python3.8/dist-packages/sklearn/manifold/_t_sne.py:790: FutureWarning: The default learning rate in TSNE will change from 200.0 to 'auto' in 1.2.
  warnings.warn(
../_images/notebooks_Occupancy_gcce_10_1.png
[8]:

Y = Y - 1 t = t - 1

[9]:
from sklearn.metrics import classification_report
for i in range(Y.shape[1]):
    print('annotator',i+1)
    print(classification_report(t,Y[:,i]))
    unique, counts = np.unique(Y[:,i], return_counts=True)
    plt.figure()
    plt.bar(unique, counts)
#     unique, counts = np.unique(Y_test[5], return_counts=True)
#     plt.bar(unique, counts)

    plt.title('Class Frequency for Y_true')
    plt.xlabel('Class')
    plt.ylabel('Frequency')

annotator 1
              precision    recall  f1-score   support

           0       1.00      0.76      0.86      1693
           1       0.70      1.00      0.83       972

    accuracy                           0.85      2665
   macro avg       0.85      0.88      0.84      2665
weighted avg       0.89      0.85      0.85      2665

annotator 2
              precision    recall  f1-score   support

           0       1.00      0.33      0.50      1693
           1       0.46      1.00      0.63       972

    accuracy                           0.58      2665
   macro avg       0.73      0.67      0.57      2665
weighted avg       0.80      0.58      0.55      2665

annotator 3
              precision    recall  f1-score   support

           0       0.74      0.96      0.84      1693
           1       0.85      0.41      0.56       972

    accuracy                           0.76      2665
   macro avg       0.80      0.69      0.70      2665
weighted avg       0.78      0.76      0.73      2665

annotator 4
              precision    recall  f1-score   support

           0       0.81      0.46      0.59      1693
           1       0.46      0.81      0.59       972

    accuracy                           0.59      2665
   macro avg       0.64      0.64      0.59      2665
weighted avg       0.69      0.59      0.59      2665

annotator 5
              precision    recall  f1-score   support

           0       0.48      0.54      0.51      1693
           1       0.00      0.00      0.00       972

    accuracy                           0.34      2665
   macro avg       0.24      0.27      0.26      2665
weighted avg       0.31      0.34      0.32      2665

../_images/notebooks_Occupancy_gcce_12_1.png
../_images/notebooks_Occupancy_gcce_12_2.png
../_images/notebooks_Occupancy_gcce_12_3.png
../_images/notebooks_Occupancy_gcce_12_4.png
../_images/notebooks_Occupancy_gcce_12_5.png

Split data

[10]:
import numpy.matlib
from sklearn.model_selection import ShuffleSplit, StratifiedShuffleSplit
Ns = 1
ss = ShuffleSplit(n_splits=Ns, test_size=0.3,random_state =123)
for train_index, test_index in ss.split(X):
    print(test_index)
    X_train, X_test,Y_train,Y_test = X[train_index,:], X[test_index,:],Y[train_index,:], Y[test_index,:]
    Y_true_train, Y_true_test = t[train_index].reshape(-1,1), t[test_index].reshape(-1,1)
print(X_train.shape, Y_train.shape, Y_true_train.shape)
[ 315  235 1480 1538 1087 1009 1677 1094  343 2175 1455 2535 2641  798
  417 2238 1781 1445   85 1828 2029 1034 1067 1458 2455  732 2434 2247
 2113 2386  689  853 2200 2500  179 1245 1758 1927  709 1826 2529 1099
  805  601 1022 1730 2135 1361 2294 2644  206  420  878 2093 1400 1518
  934 1622 1279  613  957  190   33 1450  335 1371 2634  103  304 1228
 2242 2384 1637  673  222 2340 1765  360  289   25   45 1937  537 1237
 1183 2095 2375 2379 2390 2170 2607  589 1833 2628  354  189 2016 1286
 1116  556 1918  937 1740  803 2435  257  807 1697 2494 2538  249  683
 1673 1391  871 1064 1364  814  184  498 1898 1017 1055  906  645  242
  684  779  784 1696 1226  423  966 2596  649 1008 2402  101 1283 1529
 2417 1449  616 1107 1845 1011 1572 2525 2380 2651  704 1089  466 1853
 2462 1726 2502 2479 1710 1050  469  220  336  263 1535  554 2590 1273
 2543  861  449 1224 1957 2537 1106  114 1213 2194  830  973 1504 2168
  777 1975  996 2025 2094  707  994 2315 1970  748 1982 2430 1511   43
 2291 1822 1547  958 2312 1598 1733 1587 1659  856 1654 2028 2648 2627
  148 1347 1624 1688  383  565 2572 2296  381  714   58 1032 2160  353
 2021 1000 1788 2445  524 2331 2420 1191 1278 1113  208  132 1621  875
 2400  319  800  646 2353  403 1205 1203 1685  364  129 1941 2039 1426
  591  252 2048 1489 1247  477 1633 1036 1603  706  440  576 1821 1523
 2561 2488  618  590 1362 1464 1945  395 2458 1556 2041  632 1527  720
 2337 2116 1260 1915 2211  108  658 2096 1374 1717  897 2421 2512 2003
 1809  310 1997 1394  949 2395 1706 1791 2223 2215 2047 2271 1536  243
 1310 1351   21  850 1385  723  511 2067  785  970 1840  822  439 2064
 1456 1178 2098 2410 2595 2164 1083 2622 2253 2155 1027 1206 2002 2437
  680 1727 1955 1842 1678  647 1690 1739  547 1413 1102  476 2612 1578
 1832  368  569  116   12 1227 1127 1416 2088 1907 1837  471 1373  270
 1356 2505  742 1448   24 2358  594 1938 2459 1269 2657 1925  621 2404
 1143 1015 1751 2626  493   31 2653 1430  518  221  431 1319  982  167
  671 2138  792 1867  841  110  799 2246 2115  239 1928 2317 2264  379
 1878  553 1959 1397 1611 1943 1983  224   75 2316  402  256 1002  746
 2035   63 1375 1801 2144 1265 1689 2280   18 2601 1911 2078 1342 1330
 2580  141 1383 2642 1103  328 2233  813 1066 2472 1605 1724 2598  610
  127 2051  948 1193  971 2178  682 2165 1266  988 1599  730 1077 2258
 2325  266 2092  207 2411  215 1195 1415 2469  895 1065 1167 2192   50
 1166 1035 1186 1802  196 2262 2578 2554 1156  857  380 2209  767  638
 1827 2143 2506  984  501 2456  627 2112 1208 1923 1964 2287   86 2374
  976  419 1379 1952 1380 1298 1285  597 1233 1569 2303 2569  429 1676
 1482 2332  502 1559   26  738 1117 2012 2134 2329 2102 1200 1920 1703
  991  426  327 1701  835 2151 1912 1411 1600 2497 2368 2423 1737 2193
 1910 1834  693 1090 1549 2288  352 2487 1216  558 1848 1144 2311 2083
   28 2361 1814 1420  641 2489 1657  279   72  536  909 2157  112  891
 1204  563 1098 1924  318 1046  735  797 2549 1037 1750  917  838 1042
  675  216 2565 2589  529 1179 1097 1612 2621  326 1123 1462  120 2348
 2292    5   30 2152  292 2084 1068  667 1743 1617 1471  351  749   91
 1461 2623 1020 1412 2511  593 2544 2114 2425 2352 2158 1668  228 1854
  903 2180 1671 1121  452  585 2239 2101 2214  615  463 1334 1469 1058
  100  444 1721 1808 1476 1187 1360 1670 2049 1830 1451 1798  969 2486
 2045 1052  633 1933  952  515  968  809   13  961 2310  717 1843 1051
  981 2136  410 2053  421 1967 1119 2068 1976  388  198 1695 2522 2594
  564 1446 2520 2243 2119  698 1012 2190  183  155 1340 2508 1623  500
  188 1613 2133 2122  409 1344 2476 1043 2231  406  926  504 1463 1459
 1256  775  118  804 1960  275 1306  611 1754 2454 2406  914  630 2658
 2218 1308    7  820 2422  574 1779  595  204  728  276 1276 2440 1199
  972  978 1483 1887   74  236 1234  187 1324  923  375 1805  349  350
  776 2221 2228 2020 1773 1280  606  237 2091  715  623  546 1295 2324
   84 1800 1079 1995 2279  756 2126 1473  882 2199  734 1440  157 1846
 1155 1818  193 2367 1965 2081  995 2245 1573  229   56 2125 1700  458
 1126 2278]
(1865, 4) (1865, 5) (1865, 1)

Apply MinMaxScaler

[11]:
scaler = MinMaxScaler()
scaler.fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)

Testing the Class

[12]:
from sklearn.metrics import classification_report, balanced_accuracy_score,  roc_auc_score
from sklearn.metrics import normalized_mutual_info_score, mutual_info_score, adjusted_mutual_info_score
l1 =0.1
NUM_RUNS =10
ACC = np.zeros(NUM_RUNS)
AUC = np.zeros(NUM_RUNS)
AUCSK = np.zeros(NUM_RUNS)
MI = np.zeros(NUM_RUNS)
NMI = np.zeros(NUM_RUNS)
AMI = np.zeros(NUM_RUNS)
BACC = np.zeros(NUM_RUNS)
for i in range(NUM_RUNS): #10
    print("iteration: " + str(i))

    MA = Keras_MA_GCCE(epochs=100,batch_size=64,R=5, K=len(np.unique(Y_true_train)), dropout=0.2, learning_rate=0.01,optimizer='Adam',
                l1_param=l1,  validation_split=0.30, verbose=0, q=0.1, neurons=4)

    MA.fit(X_train, Y_train)
    MA.plot_history()

    #Accuracy
    pred_2 = MA.predict(X_test)

    report = classification_report( pred_2[:,Y.shape[1]:].argmax(axis=1),Y_true_test.ravel(),output_dict=True)
    ACC[i] = report['accuracy']
    print("Validation ACC: %.4f" % (float(ACC[i])))


    # balanced. Accurcy
    BACC[i] = balanced_accuracy_score(Y_true_test.squeeze(), pred_2[:,Y.shape[1]:].argmax(axis=1).squeeze(), adjusted=True)
    print("Validation Balanced_ACC: %.4f" % (float(BACC[i])))

    #MI

    MI[i] = mutual_info_score(Y_true_test.squeeze(), pred_2[:,Y.shape[1]:].argmax(axis=1).squeeze())
    print("Validation MI: %.4f" % (float(MI[i]),))
    NMI[i] = normalized_mutual_info_score(Y_true_test.squeeze(), pred_2[:,Y.shape[1]:].argmax(axis=1).squeeze())
    print("Validation Normalized MI: %.4f" % (float(NMI[i]),))
    AMI[i]= adjusted_mutual_info_score(Y_true_test.squeeze(), pred_2[:,Y.shape[1]:].argmax(axis=1).squeeze())
    print("Validation Adjusted MI: %.4f" % (float(AMI[i]),))


    #AUC
    val_AUC_metric = tf.keras.metrics.AUC( from_logits = True)
   # val_logits =MA.predict(X_test) # model(X_test, training=False)
    # tf.print(y_batch_val)
    val_AUC_metric.update_state(Y_true_test, pred_2[:,Y.shape[1]:].argmax(axis=1).astype('float'))

    val_AUC = val_AUC_metric.result()
    val_AUC_metric.reset_states()
    val_AUC = val_AUC.numpy()
    print("Validation aUc: %.4f" % (float(val_AUC),))
    AUC[i] = val_AUC
    val_AUC1 = roc_auc_score(ook(Y_true_test), pred_2[:,Y_train.shape[1]:])
    print("Validation aUc_Sklearn: %.4f" % (float(val_AUC1),))
    AUCSK[i] = val_AUC1

iteration: 0
../_images/notebooks_Occupancy_gcce_18_1.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9637
Validation Balanced_ACC: 0.9258
Validation MI: 0.4940
Validation Normalized MI: 0.7635
Validation Adjusted MI: 0.7633
Validation aUc: 0.9629
Validation aUc_Sklearn: 0.9890
iteration: 1
../_images/notebooks_Occupancy_gcce_18_3.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9587
Validation Balanced_ACC: 0.9199
Validation MI: 0.4824
Validation Normalized MI: 0.7431
Validation Adjusted MI: 0.7428
Validation aUc: 0.9599
Validation aUc_Sklearn: 0.9872
iteration: 2
../_images/notebooks_Occupancy_gcce_18_5.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9550
Validation Balanced_ACC: 0.9090
Validation MI: 0.4685
Validation Normalized MI: 0.7228
Validation Adjusted MI: 0.7225
Validation aUc: 0.9545
Validation aUc_Sklearn: 0.9863
iteration: 3
../_images/notebooks_Occupancy_gcce_18_7.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9587
Validation Balanced_ACC: 0.9164
Validation MI: 0.4794
Validation Normalized MI: 0.7400
Validation Adjusted MI: 0.7398
Validation aUc: 0.9582
Validation aUc_Sklearn: 0.9895
iteration: 4
../_images/notebooks_Occupancy_gcce_18_9.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9663
Validation Balanced_ACC: 0.9279
Validation MI: 0.4999
Validation Normalized MI: 0.7744
Validation Adjusted MI: 0.7742
Validation aUc: 0.9639
Validation aUc_Sklearn: 0.9905
iteration: 5
../_images/notebooks_Occupancy_gcce_18_11.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9537
Validation Balanced_ACC: 0.9054
Validation MI: 0.4640
Validation Normalized MI: 0.7164
Validation Adjusted MI: 0.7161
Validation aUc: 0.9527
Validation aUc_Sklearn: 0.9874
iteration: 6
../_images/notebooks_Occupancy_gcce_18_13.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9587
Validation Balanced_ACC: 0.9199
Validation MI: 0.4824
Validation Normalized MI: 0.7431
Validation Adjusted MI: 0.7428
Validation aUc: 0.9599
Validation aUc_Sklearn: 0.9862
iteration: 7
../_images/notebooks_Occupancy_gcce_18_15.png
25/25 [==============================] - 0s 1ms/step
Validation ACC: 0.9613
Validation Balanced_ACC: 0.9237
Validation MI: 0.4888
Validation Normalized MI: 0.7537
Validation Adjusted MI: 0.7535
Validation aUc: 0.9618
Validation aUc_Sklearn: 0.9882
iteration: 8
../_images/notebooks_Occupancy_gcce_18_17.png
25/25 [==============================] - 0s 2ms/step
Validation ACC: 0.9663
Validation Balanced_ACC: 0.9382
Validation MI: 0.5093
Validation Normalized MI: 0.7836
Validation Adjusted MI: 0.7833
Validation aUc: 0.9691
Validation aUc_Sklearn: 0.9911
iteration: 9
../_images/notebooks_Occupancy_gcce_18_19.png
25/25 [==============================] - 0s 2ms/step
Validation ACC: 0.9587
Validation Balanced_ACC: 0.9199
Validation MI: 0.4824
Validation Normalized MI: 0.7431
Validation Adjusted MI: 0.7428
Validation aUc: 0.9599
Validation aUc_Sklearn: 0.9878
[13]:

ACC
[13]:
array([0.96375, 0.95875, 0.955  , 0.95875, 0.96625, 0.95375, 0.95875,
       0.96125, 0.96625, 0.95875])
[14]:

AUC
[14]:
array([0.96289694, 0.95993757, 0.9545027 , 0.95822275, 0.96394789,
       0.95269114, 0.95993757, 0.96184593, 0.96909225, 0.95993757])
[15]:
print('Average Accuracy: ', np.round( ACC.mean(),4)*100)
print('Average std: ',np.round(np.std( ACC),4)*100)
print('==============================================')
print('Average AUC: ', np.round( AUC.mean(),4)*100)
print('Average AUC std: ',np.round(np.std( AUC),4)*100)
print('==============================================')
print('Average AUC Sklearn: ', np.round( AUCSK.mean(),4)*100)
print('Average AUC SK std: ',np.round(np.std( AUCSK),4)*100)
print('==============================================')
print('Average Balanced Accuracy: ', np.round( BACC.mean(),4)*100)
print('Average std: ',np.round(np.std( BACC),4)*100)
print('==============================================')
print('Average MI: ', np.round( MI.mean(),4)*100)
print('Average std: ',np.round(np.std(MI),4)*100)
print('==============================================')
print('Average Normalized MI: ', np.round( NMI.mean(),4)*100)
print('Average std: ',np.round(np.std(NMI),4)*100)
print('==============================================')
print('Average Ajdusted MI: ', np.round( AMI.mean(),4)*100)
print('Average std: ',np.round(np.std(AMI),4)*100)
Average Accuracy:  96.00999999999999
Average std:  0.4
==============================================
Average AUC:  96.03
Average AUC std:  0.44
==============================================
Average AUC Sklearn:  98.83
Average AUC SK std:  0.16
==============================================
Average Balanced Accuracy:  92.06
Average std:  0.89
==============================================
Average MI:  48.51
Average std:  1.29
==============================================
Average Normalized MI:  74.83999999999999
Average std:  2.0
==============================================
Average Ajdusted MI:  74.81
Average std:  2.0
[16]:
import pickle

# create the dictionary with 6 scalar variables
Metrics = {
    'Accuracy': np.round( ACC.mean(),4)*100,
    'Accuracy_std': np.round(np.std( ACC),4)*100,
    'AUC': np.round( AUC.mean(),4)*100,
    'AUC_std': np.round(np.std( AUC),4)*100,
    'AUCSK': np.round( AUCSK.mean(),4)*100,
    'AUCSK_std': np.round(np.std( AUCSK),4)*100,
    'Balanced Accuracy': np.round( BACC.mean(),4)*100,
    'Balanced Accuracy_std':  np.round(np.std(BACC),4)*100,
    'MI': np.round( MI.mean(),4)*100,
    'MI_std': np.round(np.std(MI),4)*100,
    'Normalized MI': np.round( NMI.mean(),4)*100,
    'Normalized MI_std': np.round(np.std(NMI),4)*100,
    'Adjusted MI': np.round( AMI.mean(),4)*100,
    'Adjusted MI_std': np.round(np.std(NMI),4)*100,
}

# save the dictionary to a file using pickle
with open('data.pickle', 'wb') as handle:
    pickle.dump(Metrics, handle, protocol=pickle.HIGHEST_PROTOCOL)
Metrics
[16]:
{'Accuracy': 96.00999999999999,
 'Accuracy_std': 0.4,
 'AUC': 96.03,
 'AUC_std': 0.44,
 'AUCSK': 98.83,
 'AUCSK_std': 0.16,
 'Balanced Accuracy': 92.06,
 'Balanced Accuracy_std': 0.89,
 'MI': 48.51,
 'MI_std': 1.29,
 'Normalized MI': 74.83999999999999,
 'Normalized MI_std': 2.0,
 'Adjusted MI': 74.81,
 'Adjusted MI_std': 2.0}