{"id":85,"date":"2023-11-04T10:24:50","date_gmt":"2023-11-04T10:24:50","guid":{"rendered":"https:\/\/drhack.gr\/?page_id=85"},"modified":"2023-11-04T10:24:50","modified_gmt":"2023-11-04T10:24:50","slug":"code","status":"publish","type":"page","link":"https:\/\/drhack.gr\/?page_id=85","title":{"rendered":"code"},"content":{"rendered":"<ul class=\"wp-block-archives-list wp-block-archives\">\t<li><a href='https:\/\/drhack.gr\/?m=202208'>\u0391\u03cd\u03b3\u03bf\u03c5\u03c3\u03c4\u03bf\u03c2 2022<\/a><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-9050ab25-38d5-4bcf-9e10-16654f01864a\" href=\"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/11\/test.png\">test<\/a><a href=\"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/11\/test.png\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-9050ab25-38d5-4bcf-9e10-16654f01864a\">\u039b\u03ae\u03c8\u03b7<\/a><\/div>\n\n\n<ul class=\"wp-block-archives-list wp-block-archives\">\t<li><a href='https:\/\/drhack.gr\/?m=202208'>\u0391\u03cd\u03b3\u03bf\u03c5\u03c3\u03c4\u03bf\u03c2 2022<\/a><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-39097361-3852-48e7-9811-160f2807d05c\" href=\"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/11\/rpi3_hARDWARE-scaled.jpg\">rpi3_hARDWARE<\/a><a href=\"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/11\/rpi3_hARDWARE-scaled.jpg\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-39097361-3852-48e7-9811-160f2807d05c\">\u039b\u03ae\u03c8\u03b7<\/a><\/div>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-bb7f4cf1-ea60-4dd5-900f-a48d9833370b\" href=\"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/11\/interferencereport40.html\">interferencereport40<\/a><a href=\"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/11\/interferencereport40.html\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-bb7f4cf1-ea60-4dd5-900f-a48d9833370b\">\u039b\u03ae\u03c8\u03b7<\/a><\/div>\n\n\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Details<\/summary>\n<p>DWT4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\nimport tensorflow as tf\r\nimport numpy as np\r\nimport pandas as pd\r\nimport pydot\r\nimport graphviz\r\nfrom tensorflow import keras\r\nfrom tensorflow.keras import layers\r\nimport tkinter as tk\r\n\r\n\r\nfile_url = \"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/04\/DWT-4levels-ECG01NST-60x89-Last.csv\"\r\ndataframe = pd.read_csv(file_url)\r\n\r\n\r\n\r\n\r\n\r\ndataframe.shape\r\n\r\n\r\n\r\ndataframe.head()\r\n\r\n\r\n\r\n\r\nval_dataframe = dataframe.sample(frac=0.2, random_state=1337)\r\ntrain_dataframe = dataframe.drop(val_dataframe.index)\r\n\r\nprint(\r\n    \"Using %d samples for training and %d for validation\"\r\n    % (len(train_dataframe), len(val_dataframe))\r\n)\r\n\r\n\r\n\r\n\r\n\r\ndef dataframe_to_dataset(dataframe):\r\n    dataframe = dataframe.copy()\r\n    labels = dataframe.pop(\"target\")\r\n    ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))\r\n    ds = ds.shuffle(buffer_size=len(dataframe))\r\n    return ds\r\n\r\n\r\ntrain_ds = dataframe_to_dataset(train_dataframe)\r\nval_ds = dataframe_to_dataset(val_dataframe)\r\n\r\n\r\n\r\n\r\n\r\n\r\nfor x, y in train_ds.take(1):\r\n    print(\"Input:\", x)\r\n    print(\"Target:\", y)\r\n\r\n\r\n\r\n\r\ntrain_ds = train_ds.batch(32)\r\nval_ds = val_ds.batch(32)\r\n\r\n\r\n\r\n\r\nfrom tensorflow.keras.layers import IntegerLookup\r\nfrom tensorflow.keras.layers import Normalization\r\nfrom tensorflow.keras.layers import StringLookup\r\n\r\n\r\ndef encode_numerical_feature(feature, name, dataset):\r\n    # Create a Normalization layer for our feature\r\n    normalizer = Normalization()\r\n\r\n    # Prepare a Dataset that only yields our feature\r\n    feature_ds = dataset.map(lambda x, y: x&#91;name])\r\n    feature_ds = feature_ds.map(lambda x: tf.expand_dims(x, -1))\r\n\r\n    # Learn the statistics of the data\r\n    normalizer.adapt(feature_ds)\r\n\r\n    # Normalize the input feature\r\n    encoded_feature = normalizer(feature)\r\n    return encoded_feature\r\n\r\n\r\ndef encode_categorical_feature(feature, name, dataset, is_string):\r\n    lookup_class = StringLookup if is_string else IntegerLookup\r\n    # Create a lookup layer which will turn strings into integer indices\r\n    lookup = lookup_class(output_mode=\"binary\")\r\n\r\n    # Prepare a Dataset that only yields our feature\r\n    feature_ds = dataset.map(lambda x, y: x&#91;name])\r\n    feature_ds = feature_ds.map(lambda x: tf.expand_dims(x, -1))\r\n\r\n    # Learn the set of possible string values and assign them a fixed integer index\r\n    lookup.adapt(feature_ds)\r\n\r\n    # Turn the string input into integer indices\r\n    encoded_feature = lookup(feature)\r\n    return encoded_feature\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# Categorical features encoded as integers\r\nECG = keras.Input(shape=(1,), name=\"ECG\", dtype=\"int64\")\r\n\r\n# Categorical feature encoded as string\r\nGROUP = keras.Input(shape=(1,), name=\"GROUP\", dtype=\"string\")\r\n\r\n# Numerical features\r\nDWTBPM1 = keras.Input(shape=(1,), name=\"DWTBPM1\")\r\nDWTBPM2 = keras.Input(shape=(1,), name=\"DWTBPM2\")\r\nDWTBPM3 = keras.Input(shape=(1,), name=\"DWTBPM3\")\r\nDWTBPM4 = keras.Input(shape=(1,), name=\"DWTBPM4\")\r\nDWTBPM5 = keras.Input(shape=(1,), name=\"DWTBPM5\")\r\nDWTBPM6 = keras.Input(shape=(1,), name=\"DWTBPM6\")\r\nDWTBPM7 = keras.Input(shape=(1,), name=\"DWTBPM7\")\r\nDWTBPM8 = keras.Input(shape=(1,), name=\"DWTBPM8\")\r\nDWTBPM9 = keras.Input(shape=(1,), name=\"DWTBPM9\")\r\nDWTBPM10 = keras.Input(shape=(1,), name=\"DWTBPM10\")\r\nDWTBPM11 = keras.Input(shape=(1,), name=\"DWTBPM11\")\r\nDWTBPM12 = keras.Input(shape=(1,), name=\"DWTBPM12\")\r\nDWTBPM13 = keras.Input(shape=(1,), name=\"DWTBPM13\")\r\nDWTBPM14 = keras.Input(shape=(1,), name=\"DWTBPM14\")\r\nDWTBPM15 = keras.Input(shape=(1,), name=\"DWTBPM15\")\r\nDWTBPM16 = keras.Input(shape=(1,), name=\"DWTBPM16\")\r\nDWTBPM17 = keras.Input(shape=(1,), name=\"DWTBPM17\")\r\nDWTBPM18 = keras.Input(shape=(1,), name=\"DWTBPM18\")\r\nDWTBPM19 = keras.Input(shape=(1,), name=\"DWTBPM19\")\r\nDWTBPM20 = keras.Input(shape=(1,), name=\"DWTBPM20\")\r\nDWTBPM21 = keras.Input(shape=(1,), name=\"DWTBPM21\")\r\nDWTBPM22 = keras.Input(shape=(1,), name=\"DWTBPM22\")\r\nDWTBPM23 = keras.Input(shape=(1,), name=\"DWTBPM23\")\r\nDWTBPM24 = keras.Input(shape=(1,), name=\"DWTBPM24\")\r\nDWTBPM25 = keras.Input(shape=(1,), name=\"DWTBPM25\")\r\nDWTBPM26 = keras.Input(shape=(1,), name=\"DWTBPM26\")\r\nDWTBPM27 = keras.Input(shape=(1,), name=\"DWTBPM27\")\r\nDWTBPM28 = keras.Input(shape=(1,), name=\"DWTBPM28\")\r\nDWTBPM29 = keras.Input(shape=(1,), name=\"DWTBPM29\")\r\nDWTBPM30 = keras.Input(shape=(1,), name=\"DWTBPM30\")\r\nDWTBPM31 = keras.Input(shape=(1,), name=\"DWTBPM31\")\r\nDWTBPM32 = keras.Input(shape=(1,), name=\"DWTBPM32\")\r\nDWTBPM33 = keras.Input(shape=(1,), name=\"DWTBPM33\")\r\nDWTBPM34 = keras.Input(shape=(1,), name=\"DWTBPM34\")\r\nDWTBPM35 = keras.Input(shape=(1,), name=\"DWTBPM35\")\r\nDWTBPM36 = keras.Input(shape=(1,), name=\"DWTBPM36\")\r\nDWTBPM37 = keras.Input(shape=(1,), name=\"DWTBPM37\")\r\nDWTBPM38 = keras.Input(shape=(1,), name=\"DWTBPM38\")\r\nDWTBPM39 = keras.Input(shape=(1,), name=\"DWTBPM39\")\r\nDWTBPM40 = keras.Input(shape=(1,), name=\"DWTBPM40\")\r\nDWTBPM41 = keras.Input(shape=(1,), name=\"DWTBPM41\")\r\nDWTBPM42 = keras.Input(shape=(1,), name=\"DWTBPM42\")\r\nDWTBPM43 = keras.Input(shape=(1,), name=\"DWTBPM43\")\r\nDWTBPM44 = keras.Input(shape=(1,), name=\"DWTBPM44\")\r\nDWTBPM45 = keras.Input(shape=(1,), name=\"DWTBPM45\")\r\nDWTBPM46 = keras.Input(shape=(1,), name=\"DWTBPM46\")\r\nDWTBPM47 = keras.Input(shape=(1,), name=\"DWTBPM47\")\r\nDWTBPM48 = keras.Input(shape=(1,), name=\"DWTBPM48\")\r\nDWTBPM49 = keras.Input(shape=(1,), name=\"DWTBPM49\")\r\nDWTBPM50 = keras.Input(shape=(1,), name=\"DWTBPM50\")\r\nDWTBPM51 = keras.Input(shape=(1,), name=\"DWTBPM51\")\r\nDWTBPM52 = keras.Input(shape=(1,), name=\"DWTBPM52\")\r\nDWTBPM53 = keras.Input(shape=(1,), name=\"DWTBPM53\")\r\nDWTBPM54 = keras.Input(shape=(1,), name=\"DWTBPM54\")\r\nDWTBPM55 = keras.Input(shape=(1,), name=\"DWTBPM55\")\r\nDWTBPM56 = keras.Input(shape=(1,), name=\"DWTBPM56\")\r\nDWTBPM57 = keras.Input(shape=(1,), name=\"DWTBPM57\")\r\nDWTBPM58 = keras.Input(shape=(1,), name=\"DWTBPM58\")\r\nDWTBPM59 = keras.Input(shape=(1,), name=\"DWTBPM59\")\r\nDWTBPM60 = keras.Input(shape=(1,), name=\"DWTBPM60\")\r\nDWTBPM61 = keras.Input(shape=(1,), name=\"DWTBPM61\")\r\nDWTBPM62 = keras.Input(shape=(1,), name=\"DWTBPM62\")\r\nDWTBPM63 = keras.Input(shape=(1,), name=\"DWTBPM63\")\r\nDWTBPM64 = keras.Input(shape=(1,), name=\"DWTBPM64\")\r\nDWTBPM65 = keras.Input(shape=(1,), name=\"DWTBPM65\")\r\nDWTBPM66 = keras.Input(shape=(1,), name=\"DWTBPM66\")\r\nDWTBPM67 = keras.Input(shape=(1,), name=\"DWTBPM67\")\r\nDWTBPM68 = keras.Input(shape=(1,), name=\"DWTBPM68\")\r\nDWTBPM69 = keras.Input(shape=(1,), name=\"DWTBPM69\")\r\nDWTBPM70 = keras.Input(shape=(1,), name=\"DWTBPM70\")\r\nDWTBPM71 = keras.Input(shape=(1,), name=\"DWTBPM71\")\r\nDWTBPM72 = keras.Input(shape=(1,), name=\"DWTBPM72\")\r\nDWTBPM73 = keras.Input(shape=(1,), name=\"DWTBPM73\")\r\nDWTBPM74 = keras.Input(shape=(1,), name=\"DWTBPM74\")\r\nDWTBPM75 = keras.Input(shape=(1,), name=\"DWTBPM75\")\r\nDWTBPM76 = keras.Input(shape=(1,), name=\"DWTBPM76\")\r\nDWTBPM77 = keras.Input(shape=(1,), name=\"DWTBPM77\")\r\nDWTBPM78 = keras.Input(shape=(1,), name=\"DWTBPM78\")\r\nDWTBPM79 = keras.Input(shape=(1,), name=\"DWTBPM79\")\r\nDWTBPM80 = keras.Input(shape=(1,), name=\"DWTBPM80\")\r\nDWTBPM81 = keras.Input(shape=(1,), name=\"DWTBPM81\")\r\nDWTBPM82 = keras.Input(shape=(1,), name=\"DWTBPM82\")\r\nDWTBPM83 = keras.Input(shape=(1,), name=\"DWTBPM83\")\r\nDWTBPM84 = keras.Input(shape=(1,), name=\"DWTBPM84\")\r\nDWTBPM85 = keras.Input(shape=(1,), name=\"DWTBPM85\")\r\nDWTBPM86 = keras.Input(shape=(1,), name=\"DWTBPM86\")\r\n\r\n\r\n\r\nall_inputs = &#91;\r\n    ECG,\r\n    GROUP,\r\n    DWTBPM1, \r\n    DWTBPM2, \r\n    DWTBPM3, \r\n    DWTBPM4, \r\n    DWTBPM5, \r\n    DWTBPM6, \r\n    DWTBPM7, \r\n    DWTBPM8, \r\n    DWTBPM9,\r\n    DWTBPM10,\r\n    DWTBPM11,\r\n    DWTBPM12,\r\n    DWTBPM13,\r\n    DWTBPM14,\r\n    DWTBPM15,\r\n    DWTBPM16,\r\n    DWTBPM17,\r\n    DWTBPM18,\r\n    DWTBPM19,\r\n    DWTBPM20,\r\n    DWTBPM21,\r\n    DWTBPM22,\r\n    DWTBPM23,\r\n    DWTBPM24,\r\n    DWTBPM25,\r\n    DWTBPM26,\r\n    DWTBPM27,\r\n    DWTBPM28,\r\n    DWTBPM29,\r\n    DWTBPM30,\r\n    DWTBPM31,\r\n    DWTBPM32,\r\n    DWTBPM33,\r\n    DWTBPM34,\r\n    DWTBPM35,\r\n    DWTBPM36,\r\n    DWTBPM37,\r\n    DWTBPM38,\r\n    DWTBPM39,\r\n    DWTBPM40,\r\n    DWTBPM41,\r\n    DWTBPM42,\r\n    DWTBPM43,\r\n    DWTBPM44,\r\n    DWTBPM45,\r\n    DWTBPM46,\r\n    DWTBPM47,\r\n    DWTBPM48,\r\n    DWTBPM49,\r\n    DWTBPM50,\r\n    DWTBPM51,\r\n    DWTBPM52,\r\n    DWTBPM53,\r\n    DWTBPM54,\r\n    DWTBPM55,\r\n    DWTBPM56,\r\n    DWTBPM57,\r\n    DWTBPM58,\r\n    DWTBPM59,\r\n    DWTBPM60,\r\n    DWTBPM61,\r\n    DWTBPM62,\r\n    DWTBPM63,\r\n    DWTBPM64,\r\n    DWTBPM65,\r\n    DWTBPM66,\r\n    DWTBPM67,\r\n    DWTBPM68,\r\n    DWTBPM69,\r\n    DWTBPM70,\r\n    DWTBPM71,\r\n    DWTBPM72,\r\n    DWTBPM73,\r\n    DWTBPM74,\r\n    DWTBPM75,\r\n    DWTBPM76,\r\n    DWTBPM77,\r\n    DWTBPM78,\r\n    DWTBPM79,\r\n    DWTBPM80,\r\n    DWTBPM81,\r\n    DWTBPM82,\r\n    DWTBPM83,\r\n    DWTBPM84,\r\n    DWTBPM85,\r\n    DWTBPM86,\r\n]\r\n\r\n# Integer categorical features\r\nECG_encoded = encode_categorical_feature(ECG, \"ECG\", train_ds, False)\r\n \r\n# String categorical features\r\nGROUP_encoded = encode_categorical_feature(GROUP, \"GROUP\", train_ds, True)\r\n\r\n# Numerical features\r\nDWTBPM1_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM1\", train_ds)\r\nDWTBPM2_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM2\", train_ds)\r\nDWTBPM3_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM3\", train_ds)\r\nDWTBPM4_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM4\", train_ds)\r\nDWTBPM5_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM5\", train_ds)\r\nDWTBPM6_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM6\", train_ds)\r\nDWTBPM7_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM7\", train_ds)\r\nDWTBPM8_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM8\", train_ds)\r\nDWTBPM9_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM9\", train_ds)\r\nDWTBPM10_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM1\", train_ds)\r\nDWTBPM11_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM11\", train_ds)\r\nDWTBPM12_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM12\", train_ds)\r\nDWTBPM13_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM13\", train_ds)\r\nDWTBPM14_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM14\", train_ds)\r\nDWTBPM15_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM15\", train_ds)\r\nDWTBPM16_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM16\", train_ds)\r\nDWTBPM17_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM17\", train_ds)\r\nDWTBPM18_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM18\", train_ds)\r\nDWTBPM19_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM19\", train_ds)\r\nDWTBPM20_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM20\", train_ds)\r\nDWTBPM21_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM21\", train_ds)\r\nDWTBPM22_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM22\", train_ds)\r\nDWTBPM23_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM23\", train_ds)\r\nDWTBPM24_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM24\", train_ds)\r\nDWTBPM25_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM25\", train_ds)\r\nDWTBPM26_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM26\", train_ds)\r\nDWTBPM27_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM27\", train_ds)\r\nDWTBPM28_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM28\", train_ds)\r\nDWTBPM29_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM29\", train_ds)\r\nDWTBPM30_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM30\", train_ds)\r\nDWTBPM31_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM31\", train_ds)\r\nDWTBPM32_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM32\", train_ds)\r\nDWTBPM33_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM33\", train_ds)\r\nDWTBPM34_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM34\", train_ds)\r\nDWTBPM35_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM35\", train_ds)\r\nDWTBPM36_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM36\", train_ds)\r\nDWTBPM37_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM37\", train_ds)\r\nDWTBPM38_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM38\", train_ds)\r\nDWTBPM39_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM39\", train_ds)\r\nDWTBPM40_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM40\", train_ds)\r\nDWTBPM41_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM41\", train_ds)\r\nDWTBPM42_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM42\", train_ds)\r\nDWTBPM43_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM43\", train_ds)\r\nDWTBPM44_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM44\", train_ds)\r\nDWTBPM45_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM45\", train_ds)\r\nDWTBPM46_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM46\", train_ds)\r\nDWTBPM47_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM47\", train_ds)\r\nDWTBPM48_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM48\", train_ds)\r\nDWTBPM49_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM49\", train_ds)\r\nDWTBPM50_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM50\", train_ds)\r\nDWTBPM51_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM51\", train_ds)\r\nDWTBPM52_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM52\", train_ds)\r\nDWTBPM53_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM53\", train_ds)\r\nDWTBPM54_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM54\", train_ds)\r\nDWTBPM55_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM55\", train_ds)\r\nDWTBPM56_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM56\", train_ds)\r\nDWTBPM57_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM57\", train_ds)\r\nDWTBPM58_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM58\", train_ds)\r\nDWTBPM59_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM59\", train_ds)\r\nDWTBPM60_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM60\", train_ds)\r\nDWTBPM61_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM61\", train_ds)\r\nDWTBPM62_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM62\", train_ds)\r\nDWTBPM63_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM63\", train_ds)\r\nDWTBPM64_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM64\", train_ds)\r\nDWTBPM65_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM65\", train_ds)\r\nDWTBPM66_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM66\", train_ds)\r\nDWTBPM67_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM67\", train_ds)\r\nDWTBPM68_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM68\", train_ds)\r\nDWTBPM69_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM69\", train_ds)\r\nDWTBPM70_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM70\", train_ds)\r\nDWTBPM71_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM71\", train_ds)\r\nDWTBPM72_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM72\", train_ds)\r\nDWTBPM73_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM73\", train_ds)\r\nDWTBPM74_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM74\", train_ds)\r\nDWTBPM75_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM75\", train_ds)\r\nDWTBPM76_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM76\", train_ds)\r\nDWTBPM77_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM77\", train_ds)\r\nDWTBPM78_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM78\", train_ds)\r\nDWTBPM79_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM79\", train_ds)\r\nDWTBPM80_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM80\", train_ds)\r\nDWTBPM81_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM81\", train_ds)\r\nDWTBPM82_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM82\", train_ds)\r\nDWTBPM83_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM83\", train_ds)\r\nDWTBPM84_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM84\", train_ds)\r\nDWTBPM85_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM85\", train_ds)\r\nDWTBPM86_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM86\", train_ds)\r\n\r\n\r\nall_features = layers.concatenate(\r\n    &#91;\r\n        ECG_encoded,\r\n        GROUP_encoded,\r\n        DWTBPM1_encoded,\r\n        DWTBPM2_encoded,\r\n        DWTBPM3_encoded,\r\n        DWTBPM4_encoded,\r\n        DWTBPM5_encoded,\r\n        DWTBPM6_encoded,\r\n        DWTBPM7_encoded,\r\n        DWTBPM8_encoded,\r\n        DWTBPM9_encoded,\r\n        DWTBPM10_encoded,\r\n        DWTBPM11_encoded,\r\n        DWTBPM12_encoded,\r\n        DWTBPM13_encoded,\r\n        DWTBPM14_encoded,\r\n        DWTBPM15_encoded,\r\n        DWTBPM16_encoded,\r\n        DWTBPM17_encoded,\r\n        DWTBPM18_encoded,\r\n        DWTBPM19_encoded,\r\n        DWTBPM20_encoded,\r\n        DWTBPM21_encoded,\r\n        DWTBPM22_encoded,\r\n        DWTBPM23_encoded,\r\n        DWTBPM24_encoded,\r\n        DWTBPM25_encoded,\r\n        DWTBPM26_encoded,\r\n        DWTBPM27_encoded,\r\n        DWTBPM28_encoded,\r\n        DWTBPM29_encoded,\r\n        DWTBPM30_encoded,\r\n        DWTBPM31_encoded,\r\n        DWTBPM32_encoded,\r\n        DWTBPM33_encoded,\r\n        DWTBPM34_encoded,\r\n        DWTBPM35_encoded,\r\n        DWTBPM36_encoded,\r\n        DWTBPM37_encoded,\r\n        DWTBPM38_encoded,\r\n        DWTBPM39_encoded,\r\n        DWTBPM40_encoded,\r\n        DWTBPM41_encoded,\r\n        DWTBPM42_encoded,\r\n        DWTBPM43_encoded,\r\n        DWTBPM44_encoded,\r\n        DWTBPM45_encoded,\r\n        DWTBPM46_encoded,\r\n        DWTBPM47_encoded,\r\n        DWTBPM48_encoded,\r\n        DWTBPM49_encoded,\r\n        DWTBPM50_encoded,\r\n        DWTBPM51_encoded,\r\n        DWTBPM52_encoded,\r\n        DWTBPM53_encoded,\r\n        DWTBPM54_encoded,\r\n        DWTBPM55_encoded,\r\n        DWTBPM56_encoded,\r\n        DWTBPM57_encoded,\r\n        DWTBPM58_encoded,\r\n        DWTBPM59_encoded,\r\n        DWTBPM60_encoded,\r\n        DWTBPM61_encoded,\r\n        DWTBPM62_encoded,\r\n        DWTBPM63_encoded,\r\n        DWTBPM64_encoded,\r\n        DWTBPM65_encoded,\r\n        DWTBPM66_encoded,\r\n        DWTBPM67_encoded,\r\n        DWTBPM68_encoded,\r\n        DWTBPM69_encoded,\r\n        DWTBPM70_encoded,\r\n        DWTBPM71_encoded,\r\n        DWTBPM72_encoded,\r\n        DWTBPM73_encoded,\r\n        DWTBPM74_encoded,\r\n        DWTBPM75_encoded,\r\n        DWTBPM76_encoded,\r\n        DWTBPM77_encoded,\r\n        DWTBPM78_encoded,\r\n        DWTBPM79_encoded,\r\n        DWTBPM80_encoded,\r\n        DWTBPM81_encoded,\r\n        DWTBPM82_encoded,\r\n        DWTBPM83_encoded,\r\n        DWTBPM84_encoded,\r\n        DWTBPM85_encoded,\r\n        DWTBPM86_encoded,\r\n    ]\r\n)\r\nx = layers.Dense(32, activation=\"relu\")(all_features)\r\nx = layers.Dropout(0.5)(x)\r\noutput = layers.Dense(1, activation=\"sigmoid\")(x)\r\nmodel = keras.Model(all_inputs, output)\r\nmodel.compile(\"adam\", \"binary_crossentropy\", metrics=&#91;\"accuracy\"])\r\n\r\n\r\n\r\n\r\n\r\n# `rankdir='LR'` is to make the graph horizontal.\r\nkeras.utils.plot_model(model, show_shapes=True, rankdir=\"LR\")\r\n\r\n\r\n\r\n\r\n\r\nmodel.fit(train_ds, epochs=50, validation_data=val_ds)\r\n\r\n\r\n\r\n\r\n\r\n\r\nsample = {\r\n    \"ECG\": 0,\r\n    \"GROUP\":\"T\", \r\n    \"DWTBPM1\":15.049,\r\n    \"DWTBPM2\":15.954,\r\n    \"DWTBPM3\":0.71133,\r\n    \"DWTBPM4\":-0.16943,\r\n    \"DWTBPM5\":-0.093617,\r\n    \"DWTBPM6\":-0.3758,\r\n    \"DWTBPM7\":0.4191,\r\n    \"DWTBPM8\":-0.27348,\r\n    \"DWTBPM9\":0.51794,\r\n    \"DWTBPM10\":0.7778,\r\n    \"DWTBPM11\":-0.37705,\r\n    \"DWTBPM12\":-0.43298,\r\n    \"DWTBPM13\":0.49203,\r\n    \"DWTBPM14\":-0.50637,\r\n    \"DWTBPM15\":10.312,\r\n    \"DWTBPM16\":0.11405,\r\n    \"DWTBPM17\":0.87534,\r\n    \"DWTBPM18\":-0.41432,\r\n    \"DWTBPM19\":0.93978,\r\n    \"DWTBPM20\":0.11845,\r\n    \"DWTBPM21\":-0.18828,\r\n    \"DWTBPM22\":-0.2243,\r\n    \"DWTBPM23\":-0.16092,\r\n    \"DWTBPM24\":-0.16067,\r\n    \"DWTBPM25\":-0.17874,\r\n    \"DWTBPM26\":-0.35341,\r\n    \"DWTBPM27\":0.82711,\r\n    \"DWTBPM28\":-0.35977,\r\n    \"DWTBPM29\":0.80043,\r\n    \"DWTBPM30\":0.41024,\r\n    \"DWTBPM31\":-0.0053516,\r\n    \"DWTBPM32\":-0.00056808,\r\n    \"DWTBPM33\":-0.13293,\r\n    \"DWTBPM34\":-0.19591,\r\n    \"DWTBPM35\":-0.25608,\r\n    \"DWTBPM36\":0.73422,\r\n    \"DWTBPM37\":-0.29908,\r\n    \"DWTBPM38\":10.422,\r\n    \"DWTBPM39\":0.31114,\r\n    \"DWTBPM40\":-0.16143,\r\n    \"DWTBPM41\":-0.287,\r\n    \"DWTBPM42\":0.33273,\r\n    \"DWTBPM43\":-0.05755,\r\n    \"DWTBPM44\":0.42025,\r\n    \"DWTBPM45\":10.731,\r\n    \"DWTBPM46\":-0.4099,\r\n    \"DWTBPM47\":-0.18027,\r\n    \"DWTBPM48\":-0.24305,\r\n    \"DWTBPM49\":-0.46275,\r\n    \"DWTBPM50\":0.57248,\r\n    \"DWTBPM51\":-0.21145,\r\n    \"DWTBPM52\":0.44987,\r\n    \"DWTBPM53\":0.78692,\r\n    \"DWTBPM54\":-0.31844,\r\n    \"DWTBPM55\":-0.23371,\r\n    \"DWTBPM56\":-0.052245,\r\n    \"DWTBPM57\":0.15358,\r\n    \"DWTBPM58\":-0.066129,\r\n    \"DWTBPM59\":13.377,\r\n    \"DWTBPM60\":-0.28406,\r\n    \"DWTBPM61\":-0.18193,\r\n    \"DWTBPM62\":-0.38386,\r\n    \"DWTBPM63\":-0.18971,\r\n    \"DWTBPM64\":0.42986,\r\n    \"DWTBPM65\":-0.30491,\r\n    \"DWTBPM66\":12.464,\r\n    \"DWTBPM67\":-0.11152,\r\n    \"DWTBPM68\":-0.18534,\r\n    \"DWTBPM69\":-0.38486,\r\n    \"DWTBPM70\":0.23502,\r\n    \"DWTBPM71\":-0.11435,\r\n    \"DWTBPM72\":0.31003,\r\n    \"DWTBPM73\":0.93679,\r\n    \"DWTBPM74\":-0.43053,\r\n    \"DWTBPM75\":-0.20893,\r\n    \"DWTBPM76\":-0.45197,\r\n    \"DWTBPM77\":0.40383,\r\n    \"DWTBPM78\":-0.29302,\r\n    \"DWTBPM79\":0.5754,\r\n    \"DWTBPM80\":0.68984,\r\n    \"DWTBPM81\":-0.3486,\r\n    \"DWTBPM82\":-0.1586,\r\n    \"DWTBPM83\":-0.37793,\r\n    \"DWTBPM84\":-0.36735,\r\n    \"DWTBPM85\":-0.37782,\r\n    \"DWTBPM86\":-0.37729,\r\n \r\n    }\r\n\r\ninput_dict = {name: tf.convert_to_tensor(&#91;value]) for name, value in sample.items()}\r\npredictions = model.predict(input_dict)\r\n\r\nprint(\r\n    \"This particular patient had a %.1f percent probability \"\r\n    \"of having a heart disease, as evaluated by our model.\" % (100 * predictions&#91;0]&#91;0],)\r\n)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nsample = {\r\n    \"ECG\": 0,\r\n    \"GROUP\":\"N\", \r\n    \"DWTBPM1\":15.049,\r\n    \"DWTBPM2\":15.954,\r\n    \"DWTBPM3\":0.71133,\r\n    \"DWTBPM4\":-0.16943,\r\n    \"DWTBPM5\":-0.093617,\r\n    \"DWTBPM6\":-0.3758,\r\n    \"DWTBPM7\":0.4191,\r\n    \"DWTBPM8\":-0.27348,\r\n    \"DWTBPM9\":0.51794,\r\n    \"DWTBPM10\":0.7778,\r\n    \"DWTBPM11\":-0.37705,\r\n    \"DWTBPM12\":-0.43298,\r\n    \"DWTBPM13\":0.49203,\r\n    \"DWTBPM14\":-0.50637,\r\n    \"DWTBPM15\":10.312,\r\n    \"DWTBPM16\":0.11405,\r\n    \"DWTBPM17\":0.87534,\r\n    \"DWTBPM18\":-0.41432,\r\n    \"DWTBPM19\":0.93978,\r\n    \"DWTBPM20\":0.11845,\r\n    \"DWTBPM21\":-0.18828,\r\n    \"DWTBPM22\":-0.2243,\r\n    \"DWTBPM23\":-0.16092,\r\n    \"DWTBPM24\":-0.16067,\r\n    \"DWTBPM25\":-0.17874,\r\n    \"DWTBPM26\":-0.35341,\r\n    \"DWTBPM27\":0.82711,\r\n    \"DWTBPM28\":-0.35977,\r\n    \"DWTBPM29\":0.80043,\r\n    \"DWTBPM30\":0.41024,\r\n    \"DWTBPM31\":-0.0053516,\r\n    \"DWTBPM32\":-0.00056808,\r\n    \"DWTBPM33\":-0.13293,\r\n    \"DWTBPM34\":-0.19591,\r\n    \"DWTBPM35\":-0.25608,\r\n    \"DWTBPM36\":0.73422,\r\n    \"DWTBPM37\":-0.29908,\r\n    \"DWTBPM38\":10.422,\r\n    \"DWTBPM39\":0.31114,\r\n    \"DWTBPM40\":-0.16143,\r\n    \"DWTBPM41\":-0.287,\r\n    \"DWTBPM42\":0.33273,\r\n    \"DWTBPM43\":-0.05755,\r\n    \"DWTBPM44\":0.42025,\r\n    \"DWTBPM45\":10.731,\r\n    \"DWTBPM46\":-0.4099,\r\n    \"DWTBPM47\":-0.18027,\r\n    \"DWTBPM48\":-0.24305,\r\n    \"DWTBPM49\":-0.46275,\r\n    \"DWTBPM50\":0.57248,\r\n    \"DWTBPM51\":-0.21145,\r\n    \"DWTBPM52\":0.44987,\r\n    \"DWTBPM53\":0.78692,\r\n    \"DWTBPM54\":-0.31844,\r\n    \"DWTBPM55\":-0.23371,\r\n    \"DWTBPM56\":-0.052245,\r\n    \"DWTBPM57\":0.15358,\r\n    \"DWTBPM58\":-0.066129,\r\n    \"DWTBPM59\":13.377,\r\n    \"DWTBPM60\":-0.28406,\r\n    \"DWTBPM61\":-0.18193,\r\n    \"DWTBPM62\":-0.38386,\r\n    \"DWTBPM63\":-0.18971,\r\n    \"DWTBPM64\":0.42986,\r\n    \"DWTBPM65\":-0.30491,\r\n    \"DWTBPM66\":12.464,\r\n    \"DWTBPM67\":-0.11152,\r\n    \"DWTBPM68\":-0.18534,\r\n    \"DWTBPM69\":-0.38486,\r\n    \"DWTBPM70\":0.23502,\r\n    \"DWTBPM71\":-0.11435,\r\n    \"DWTBPM72\":0.31003,\r\n    \"DWTBPM73\":0.93679,\r\n    \"DWTBPM74\":-0.43053,\r\n    \"DWTBPM75\":-0.20893,\r\n    \"DWTBPM76\":-0.45197,\r\n    \"DWTBPM77\":0.40383,\r\n    \"DWTBPM78\":-0.29302,\r\n    \"DWTBPM79\":0.5754,\r\n    \"DWTBPM80\":0.68984,\r\n    \"DWTBPM81\":-0.3486,\r\n    \"DWTBPM82\":-0.1586,\r\n    \"DWTBPM83\":-0.37793,\r\n    \"DWTBPM84\":-0.36735,\r\n    \"DWTBPM85\":-0.37782,\r\n    \"DWTBPM86\":-0.37729,\r\n \r\n    }\r\n\r\ninput_dict = {name: tf.convert_to_tensor(&#91;value]) for name, value in sample.items()}\r\npredictions = model.predict(input_dict)\r\n\r\nprint(\r\n    \"This particular patient had a %.1f percent probability \"\r\n    \"of having a heart disease, as evaluated by our model.\" % (100 * predictions&#91;0]&#91;0],)\r\n)\r\n\r\n\r\n\r\n\r\n\r\n\r\n<\/code><\/pre>\n<\/details>\n\n\n\n<pre class=\"wp-block-code\"><code>#POWERTOP\n\n\n\n#!\/bin\/bash\r\n\r\n# \u0391\u03c1\u03b9\u03b8\u03bc\u03cc\u03c2 \u03bc\u03b5\u03c4\u03c1\u03ae\u03c3\u03b5\u03c9\u03bd\r\nnum_measurements=10\r\n\r\n# \u0394\u03b9\u03ac\u03c1\u03ba\u03b5\u03b9\u03b1 \u03ba\u03ac\u03b8\u03b5 \u03bc\u03ad\u03c4\u03c1\u03b7\u03c3\u03b7\u03c2 \u03c3\u03b5 \u03b4\u03b5\u03c5\u03c4\u03b5\u03c1\u03cc\u03bb\u03b5\u03c0\u03c4\u03b1\r\nmeasurement_duration=1\r\n\r\n# \u0394\u03b9\u03b5\u03cd\u03b8\u03c5\u03bd\u03c3\u03b7 \u03b5\u03be\u03cc\u03b4\u03bf\u03c5\r\noutput_directory=\"\/Desktop\/project\"\r\n\r\n# \u0394\u03b7\u03bc\u03b9\u03bf\u03c5\u03c1\u03b3\u03af\u03b1 \u03c4\u03bf\u03c5 \u03c6\u03b1\u03ba\u03ad\u03bb\u03bf\u03c5 \u03b5\u03be\u03cc\u03b4\u03bf\u03c5 \u03b1\u03bd \u03b4\u03b5\u03bd \u03c5\u03c0\u03ac\u03c1\u03c7\u03b5\u03b9\r\nmkdir -p \"metriseis\"\r\n\r\n# \u03a0\u03af\u03bd\u03b1\u03ba\u03b1\u03c2 \u03b3\u03b9\u03b1 \u03b1\u03c0\u03bf\u03b8\u03ae\u03ba\u03b5\u03c5\u03c3\u03b7 \u03c4\u03c9\u03bd \u03c4\u03b9\u03bc\u03ce\u03bd \u03b9\u03c3\u03c7\u03cd\u03bf\u03c2\r\npower_values=()\r\ny=$(echo \"scale=2; $x \/ $num_measurements\" | bc)\r\necho \"The value of y is $power_values \"\r\n# \u0395\u03c0\u03b1\u03bd\u03ac\u03bb\u03b7\u03c8\u03b7 \u03b3\u03b9\u03b1 \u03c4\u03b9\u03c2 \u03bc\u03b5\u03c4\u03c1\u03ae\u03c3\u03b5\u03b9\u03c2\r\nfor ((i=1; i&lt;=$num_measurements; i++)); do\r\n    # \u039f\u03c1\u03b9\u03c3\u03bc\u03cc\u03c2 \u03c4\u03bf\u03c5 \u03bf\u03bd\u03cc\u03bc\u03b1\u03c4\u03bf\u03c2 \u03c4\u03bf\u03c5 \u03b1\u03c1\u03c7\u03b5\u03af\u03bf\u03c5 \u03b5\u03be\u03cc\u03b4\u03bf\u03c5\r\n    output_file=\"Measurement_$i.html\"\r\n    \r\n    # \u0395\u03ba\u03c4\u03ad\u03bb\u03b5\u03c3\u03b7 \u03c4\u03bf\u03c5 powertop \u03bc\u03b5 \u03c4\u03b7\u03bd \u03ba\u03b1\u03b8\u03bf\u03c1\u03b9\u03c3\u03bc\u03ad\u03bd\u03b7 \u03b4\u03b9\u03ac\u03c1\u03ba\u03b5\u03b9\u03b1 \u03ba\u03b1\u03b9 \u03b1\u03c0\u03bf\u03b8\u03ae\u03ba\u03b5\u03c5\u03c3\u03b7 \u03c4\u03c9\u03bd \u03b1\u03c0\u03bf\u03c4\u03b5\u03bb\u03b5\u03c3\u03bc\u03ac\u03c4\u03c9\u03bd \u03c3\u03b5 \u03bc\u03bf\u03c1\u03c6\u03ae HTML\r\n    sudo powertop --time=$measurement_duration --html=\"$output_file\"\r\n    \r\n    echo \"\u039f\u03bb\u03bf\u03ba\u03bb\u03ae\u03c1\u03c9\u03c3\u03b7 \u039c\u03ad\u03c4\u03c1\u03b7\u03c3\u03b7\u03c2 $i.\"\r\n    x=$((power_value + x))\r\n    # \u0395\u03be\u03b1\u03b3\u03c9\u03b3\u03ae \u03c4\u03b7\u03c2 \u03c4\u03b9\u03bc\u03ae\u03c2 \u03c4\u03b7\u03c2 \u03b9\u03c3\u03c7\u03cd\u03bf\u03c2 \u03b1\u03c0\u03cc \u03c4\u03b7\u03bd \u03b1\u03bd\u03b1\u03c6\u03bf\u03c1\u03ac HTML (\u03c0\u03c1\u03bf\u03c3\u03b1\u03c1\u03bc\u03cc\u03c3\u03c4\u03b5 \u03b1\u03bd\u03ac\u03bb\u03bf\u03b3\u03b1)\r\n    power_value=$(grep \"\u039a\u03b1\u03c4\u03b1\u03bd\u03ac\u03bb\u03c9\u03c3\u03b7 \u0399\u03c3\u03c7\u03cd\u03bf\u03c2\" \"$output_file\" | awk '{print $4}')\r\n    \r\n    #echo \"The value of x is $x\"\r\n    \r\n    # \u03a0\u03c1\u03bf\u03c3\u03ac\u03c1\u03c4\u03b7\u03c3\u03b7 \u03c4\u03b7\u03c2 \u03c4\u03b9\u03bc\u03ae\u03c2 \u03c4\u03b7\u03c2 \u03b9\u03c3\u03c7\u03cd\u03bf\u03c2 \u03c3\u03c4\u03bf\u03bd \u03c0\u03af\u03bd\u03b1\u03ba\u03b1\r\n    power_values+=(\"$power_value\")\r\n    \r\n    # \u0391\u03bd\u03b1\u03bc\u03bf\u03bd\u03ae \u03b3\u03b9\u03b1 \u03bb\u03af\u03b3\u03b1 \u03b4\u03b5\u03c5\u03c4\u03b5\u03c1\u03cc\u03bb\u03b5\u03c0\u03c4\u03b1 \u03b1\u03bd\u03ac\u03bc\u03b5\u03c3\u03b1 \u03c3\u03c4\u03b9\u03c2 \u03bc\u03b5\u03c4\u03c1\u03ae\u03c3\u03b5\u03b9\u03c2 (\u03c0\u03c1\u03bf\u03c3\u03b1\u03c1\u03bc\u03cc\u03c3\u03c4\u03b5 \u03ba\u03b1\u03c4\u03ac \u03c4\u03b7\u03bd \u03b5\u03c0\u03b9\u03bb\u03bf\u03b3\u03ae \u03c3\u03b1\u03c2)\r\n    sleep 0 \r\n    \r\ndone\r\n\r\n\r\n\r\n\r\n# \u03a5\u03c0\u03bf\u03bb\u03bf\u03b3\u03b9\u03c3\u03bc\u03cc\u03c2 \u03c4\u03b7\u03c2 \u03bc\u03ad\u03c3\u03b7\u03c2 \u03ba\u03b1\u03c4\u03b1\u03bd\u03ac\u03bb\u03c9\u03c3\u03b7\u03c2 \u03b9\u03c3\u03c7\u03cd\u03bf\u03c2\r\n\u03c3\u03c5\u03bd\u03bf\u03bb\u03b9\u03ba\u03ae_\u03b9\u03c3\u03c7\u03cd\u03c2=0\r\nfor power_value in \"${power_values&#91;@]}\"; do\r\n    \u03c3\u03c5\u03bd\u03bf\u03bb\u03b9\u03ba\u03ae_\u03b9\u03c3\u03c7\u03cd\u03c2=$(echo \"$\u03c3\u03c5\u03bd\u03bf\u03bb\u03b9\u03ba\u03ae_\u03b9\u03c3\u03c7\u03cd\u03c2 + $power_value\" | bc)\r\ndone\r\n\r\n\u03bc\u03ad\u03c3\u03b7_\u03b9\u03c3\u03c7\u03cd\u03c2=$(echo \"$\u03c3\u03c5\u03bd\u03bf\u03bb\u03b9\u03ba\u03ae_\u03b9\u03c3\u03c7\u03cd\u03c2 \/ $num_measurements\" | bc)\r\n\r\necho \"\u039c\u03ad\u03c3\u03b7 \u039a\u03b1\u03c4\u03b1\u03bd\u03ac\u03bb\u03c9\u03c3\u03b7 \u0399\u03c3\u03c7\u03cd\u03bf\u03c2: $\u03bc\u03ad\u03c3\u03b7_\u03b9\u03c3\u03c7\u03cd\u03c2 Watts\"\r\n\r\necho \"\u039f\u03bb\u03bf\u03ba\u03bb\u03ae\u03c1\u03c9\u03c3\u03b7 \u03cc\u03bb\u03c9\u03bd \u03c4\u03c9\u03bd \u03bc\u03b5\u03c4\u03c1\u03ae\u03c3\u03b5\u03c9\u03bd.\"\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#code Hjorth parameters\n\n\n# -*- coding: utf-8 -*-\r\n#source Desktop\/project\/env\/bin\/activate \r\n#python\r\n\r\nimport tensorflow as tf\r\nimport numpy as np\r\nimport pandas as pd\r\nimport pydot\r\nimport graphviz\r\nfrom tensorflow import keras\r\nfrom tensorflow.keras import layers\r\nimport tkinter as tk\r\nfrom tensorflow.keras.layers import IntegerLookup\r\nfrom tensorflow.keras.layers import Normalization\r\nfrom tensorflow.keras.layers import StringLookup\r\nimport Adafruit_CharLCD as LCD\r\nfile_url = \"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/06\/Hjorth_P_6x60_Learning_Sets-GROUPED-T_N.csv\"\r\n\r\ndataframe = pd.read_csv(file_url)\r\n\r\n\r\ndataframe.shape\r\ndataframe.head()\r\n \r\nval_dataframe = dataframe.sample(frac=0.2, random_state=1337)\r\ntrain_dataframe = dataframe.drop(val_dataframe.index)\r\n\r\nprint(\r\n    \"Using %d samples for training and %d for validation\"\r\n#     % (len(train_dataframe), len(val_dataframe))\r\n)\r\n\r\ndef dataframe_to_dataset(dataframe):\r\n    dataframe = dataframe.copy()\r\n    labels = dataframe.pop(\"target\")\r\n    ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))\r\n    ds = ds.shuffle(buffer_size=len(dataframe))\r\n    return ds\r\n\r\ntrain_ds = dataframe_to_dataset(train_dataframe)\r\nval_ds = dataframe_to_dataset(val_dataframe)\r\n\r\nfor x, y in train_ds.take(1):\r\n    print(\"Input:\", x)\r\n    print(\"Target:\", y)\r\n\r\ntrain_ds = train_ds.batch(32)\r\nval_ds = val_ds.batch(32)\r\n\r\n\r\ndef encode_numerical_feature(feature, name, dataset):\r\n    normalizer = Normalization()\r\n    feature_ds = dataset.map(lambda x, y: x&#91;name])\r\n    feature_ds = feature_ds.map(lambda x: tf.expand_dims(x, -1))  \r\n    normalizer.adapt(feature_ds)    \r\n    encoded_feature = normalizer(feature)\r\n    return encoded_feature\r\n\r\ndef encode_categorical_feature(feature, name, dataset, is_string):\r\n    lookup_class = StringLookup if is_string else IntegerLookup\r\n    lookup = lookup_class(output_mode=\"binary\")\r\n    feature_ds = dataset.map(lambda x, y: x&#91;name])\r\n    feature_ds = feature_ds.map(lambda x: tf.expand_dims(x, -1))\r\n    lookup.adapt(feature_ds)\r\n    encoded_feature = lookup(feature)\r\n    return encoded_feature\r\n\r\nECG = keras.Input(shape=(1,), name=\"ECG\", dtype=\"int64\")\r\nGROUP = keras.Input(shape=(1,), name=\"GROUP\", dtype=\"string\")\r\nHjorthBPM1= keras.Input(shape=(1,), name=\"HjorthBPM1\")\r\nHjorthBPM2 = keras.Input(shape=(1,), name=\"HjorthBPM2\")\r\nHjorthBPM3 = keras.Input(shape=(1,), name=\"HjorthBPM3\")\r\n\r\nall_inputs = &#91;\r\n\t    ECG,\r\n\t    GROUP,\r\n    \tHjorthBPM1,\r\n        HjorthBPM2,\r\n        HjorthBPM3,]\r\n        \r\nECG_encoded = encode_categorical_feature(ECG, \"ECG\", train_ds, False)\r\nGROUP_encoded = encode_categorical_feature(GROUP, \"GROUP\", train_ds, True)\r\nHjorthBPM1_encoded = encode_numerical_feature(HjorthBPM1, \"HjorthBPM1\", train_ds)\r\nHjorthBPM2_encoded = encode_numerical_feature(HjorthBPM2, \"HjorthBPM2\", train_ds)\r\nHjorthBPM3_encoded = encode_numerical_feature(HjorthBPM3, \"HjorthBPM3\", train_ds)\r\n\r\nall_features = layers.concatenate(\r\n    &#91;ECG_encoded,\r\n     GROUP_encoded,\r\n     HjorthBPM1_encoded,\r\n     HjorthBPM2_encoded,\r\n     HjorthBPM3_encoded,]\r\n)\r\n\r\nx = layers.Dense(32, activation=\"relu\")(all_features)\r\nx = layers.Dropout(0.5)(x)\r\noutput = layers.Dense(1, activation=\"sigmoid\")(x)\r\nmodel = keras.Model(all_inputs, output)\r\nmodel.compile(\"adam\", \"binary_crossentropy\", metrics=&#91;\"accuracy\"])\r\n\r\n\r\n\"\"\"Let's visualize our connectivity graph:\"\"\"\r\n\r\n# `rankdir='LR'` is to make the graph horizontal.\r\nkeras.utils.plot_model(model, show_shapes=True, rankdir=\"LR\")\r\n\r\n\"\"\"## Train the model\"\"\"\r\n\r\nmodel.fit(train_ds, epochs=250, validation_data=val_ds)\r\n\r\n\"\"\"We quickly get to 80% validation accuracy.\r\n\r\n## Inference on new data\r\n\r\nTo get a prediction for a new sample, you can simply call `model.predict()`. There are\r\njust two things you need to do:\r\n\r\n1. wrap scalars into a list so as to have a batch dimension (models only process batches\r\nof data, not single samples)\r\n2. Call `convert_to_tensor` on each feature\r\n\"\"\"\r\n\r\n\r\n# LCD pin configuration (adjust as needed)\r\nlcd_rs = 25  # RS\r\nlcd_en = 24  # EN\r\nlcd_d4 = 23  # D4\r\nlcd_d5 = 17 # D5\r\nlcd_d6 = 18  # D6\r\nlcd_d7 = 22  # D7\r\n\r\n\r\n# LCD column and row sizes (16x2 LCD in this example)\r\nlcd_columns = 16\r\nlcd_rows = 2\r\n\r\n# Create the LCD instance\r\nlcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows)\r\n\r\n\r\n\r\nX1=0.19599,\r\nX2=15.591,\r\nX3=0.55816,\r\nsample = {\r\n    \"ECG\": 0,\r\n    \"GROUP\":\"T\",\r\n    \"HjorthBPM1\":X1,\r\n    \"HjorthBPM2\":X2,\r\n    \"HjorthBPM3\":X3,}\r\n\r\ninput_dict = {name: tf.convert_to_tensor(&#91;value]) for name, value in sample.items()}\r\npredictions = model.predict(input_dict)\r\n\r\n\r\n\r\nnumber=(100*predictions&#91;0]&#91;0])\r\nrounded_number = round(number, 2)\r\nmessage=\"This particular patient had a \"\r\nmessage2=\"% of having a heart disease, as evaluated by our model.\" \r\nSuper_message=message + str(rounded_number) + message2\r\n\r\ndef display_result():\r\n    result = Super_message # Replace with your actual result\r\n    result_label.config(text=result)\r\n\r\napp = tk.Tk()\r\napp.title(\"Result for Terminating AF  \")\r\n\r\nresult_label = tk.Label(app, text=\"Terminating AF\", font=(\"Arial\", 20))\r\nresult_label.pack()\r\n\r\nshow_result_button = tk.Button(app, text=\"Show Result\", command=display_result)\r\nshow_result_button.pack()\r\n\r\n\r\n\r\nsample2 = {\r\n    \"ECG\": 0,\r\n    \"GROUP\":\"N\",\r\n    \"HjorthBPM1\":X1,\r\n    \"HjorthBPM2\":X2,\r\n    \"HjorthBPM3\":X3,}\r\n\r\ninput_dict2 = {name: tf.convert_to_tensor(&#91;value]) for name, value in sample2.items()}\r\npredictions2 = model.predict(input_dict2)\r\n\r\nnumber2=(100*predictions2&#91;0]&#91;0])\r\nrounded_number2 = round(number2, 2)\r\nSuper_message2=message + str(rounded_number2) + message2\r\n\r\ndef display_result2():\r\n    result2 = Super_message2 # Replace with your actual result\r\n    result2_label.config(text=result2)\r\n\r\napp2 = tk.Tk()\r\napp2.title(\"Result for non-terminating AF \")\r\n\r\nresult2_label = tk.Label(app2, text=\"Non-Terminating AF\", font=(\"Arial\", 20))\r\nresult2_label.pack()\r\n\r\nshow_result2_button = tk.Button(app2, text=\"Show Result2\", command=display_result2)\r\nshow_result2_button.pack()\r\n\r\n\r\n\r\nmessage3=\"NON - T.F \"\r\nmessage5=\"T.F \"\r\nmessage4 =\"%\"\r\nSuper2_message2=message3 + str(rounded_number) + message4\r\nSuper3_message2=message5 + str(rounded_number2) + message4\r\n# Display text\r\nlcd.set_cursor(0, 0)  # Set the cursor to the first line (0) and first column (0)\r\nlcd.message(Super2_message2)\r\n\r\n\r\nlcd.set_cursor(0, 1)  # Move the cursor to the first column (0) of the second line (1)\r\nlcd.message(Super3_message2)\r\n\r\n\r\napp.mainloop()\r\n\r\n# Clear the display\r\nlcd.clear()\r\n\r\n\r\n\n\n\n\n<\/code><\/pre>\n\n\n\n<p>\u039a\u03ce\u03b4\u03b9\u03ba\u03b1\u03c2 \u0391\u03c0\u03bb\u03cc\u03c2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\nimport tensorflow as tf\r\nimport numpy as np\r\nimport pandas as pd\r\nimport pydot\r\nimport graphviz\r\nfrom tensorflow import keras\r\nfrom tensorflow.keras import layers\r\nimport tkinter as tk\r\n\r\nfile_url = \"https:\/\/drhack.gr\/wp-content\/uploads\/2023\/03\/desease-asrxh-3.csv\"\r\ndataframe = pd.read_csv(file_url)\r\n\r\n\r\ndataframe.shape\r\n\r\n\r\n\r\ndataframe.head()\r\n\r\n\r\nval_dataframe = dataframe.sample(frac=0.2, random_state=1337)\r\ntrain_dataframe = dataframe.drop(val_dataframe.index)\r\n\r\nprint(\r\n    \"Using %d samples for training and %d for validation\"\r\n    % (len(train_dataframe), len(val_dataframe))\r\n)\r\n\r\n\r\n\r\ndef dataframe_to_dataset(dataframe):\r\n    dataframe = dataframe.copy()\r\n    labels = dataframe.pop(\"desease\")\r\n    ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))\r\n    ds = ds.shuffle(buffer_size=len(dataframe))\r\n    return ds\r\n\r\n\r\ntrain_ds = dataframe_to_dataset(train_dataframe)\r\nval_ds = dataframe_to_dataset(val_dataframe)\r\n\r\n\r\nfor x, y in train_ds.take(1):\r\n    print(\"Input:\", x)\r\n    print(\"desease:\", y)\r\n\r\n\r\n\r\ntrain_ds = train_ds.batch(32)\r\nval_ds = val_ds.batch(32)\r\n\r\n\r\n\r\n\r\n\r\nfrom tensorflow.keras.layers import IntegerLookup\r\nfrom tensorflow.keras.layers import Normalization\r\nfrom tensorflow.keras.layers import StringLookup\r\n\r\n\r\ndef encode_numerical_feature(feature, name, dataset):\r\n    # Create a Normalization layer for our feature\r\n    normalizer = Normalization()\r\n\r\n    # Prepare a Dataset that only yields our feature\r\n    feature_ds = dataset.map(lambda x, y: x&#91;name])\r\n    feature_ds = feature_ds.map(lambda x: tf.expand_dims(x, -1))\r\n\r\n    # Learn the statistics of the data\r\n    normalizer.adapt(feature_ds)\r\n\r\n    # Normalize the input feature\r\n    encoded_feature = normalizer(feature)\r\n    return encoded_feature\r\n\r\n\r\ndef encode_categorical_feature(feature, name, dataset, is_string):\r\n    lookup_class = StringLookup if is_string else IntegerLookup\r\n    # Create a lookup layer which will turn strings into integer indices\r\n    lookup = lookup_class(output_mode=\"binary\")\r\n\r\n    # Prepare a Dataset that only yields our feature\r\n    feature_ds = dataset.map(lambda x, y: x&#91;name])\r\n    feature_ds = feature_ds.map(lambda x: tf.expand_dims(x, -1))\r\n\r\n    # Learn the set of possible string values and assign them a fixed integer index\r\n    lookup.adapt(feature_ds)\r\n\r\n    # Turn the string input into integer indices\r\n    encoded_feature = lookup(feature)\r\n    return encoded_feature\r\n\r\n\r\n\r\n\r\n\r\n\r\n# Categorical features encoded as integers\r\nECG = keras.Input(shape=(1,), name=\"ECG\", dtype=\"int64\")\r\n\r\n# Categorical feature encoded as string\r\nGROUP = keras.Input(shape=(1,), name=\"GROUP\", dtype=\"string\")\r\n\r\n# Numerical features\r\nDWTBPM1 = keras.Input(shape=(1,), name=\"DWTBPM1\")\r\nDWTBPM2 = keras.Input(shape=(1,), name=\"DWTBPM2\")\r\nDWTBPM3 = keras.Input(shape=(1,), name=\"DWTBPM3\")\r\nDWTBPM4 = keras.Input(shape=(1,), name=\"DWTBPM4\")\r\nDWTBPM5 = keras.Input(shape=(1,), name=\"DWTBPM5\")\r\nDWTBPM6 = keras.Input(shape=(1,), name=\"DWTBPM6\")\r\nDWTBPM7 = keras.Input(shape=(1,), name=\"DWTBPM7\")\r\nDWTBPM8 = keras.Input(shape=(1,), name=\"DWTBPM8\")\r\nDWTBPM9 = keras.Input(shape=(1,), name=\"DWTBPM9\")\r\n\r\nall_inputs = &#91;\r\n    ECG,\r\n    GROUP,\r\n    DWTBPM1, \r\n    DWTBPM2, \r\n    DWTBPM3, \r\n    DWTBPM4, \r\n    DWTBPM5, \r\n    DWTBPM6, \r\n    DWTBPM7, \r\n    DWTBPM8, \r\n    DWTBPM9,\r\n]\r\n\r\n# Integer categorical features\r\nECG_encoded = encode_categorical_feature(ECG, \"ECG\", train_ds, False)\r\n \r\n# String categorical features\r\nGROUP_encoded = encode_categorical_feature(GROUP, \"GROUP\", train_ds, True)\r\n\r\n# Numerical features\r\nDWTBPM1_encoded = encode_numerical_feature(DWTBPM1, \"DWTBPM1\", train_ds)\r\nDWTBPM2_encoded = encode_numerical_feature(DWTBPM2, \"DWTBPM2\", train_ds)\r\nDWTBPM3_encoded = encode_numerical_feature(DWTBPM3, \"DWTBPM3\", train_ds)\r\nDWTBPM4_encoded = encode_numerical_feature(DWTBPM4, \"DWTBPM4\", train_ds)\r\nDWTBPM5_encoded = encode_numerical_feature(DWTBPM5, \"DWTBPM5\", train_ds)\r\nDWTBPM6_encoded = encode_numerical_feature(DWTBPM6, \"DWTBPM6\", train_ds)\r\nDWTBPM7_encoded = encode_numerical_feature(DWTBPM7, \"DWTBPM7\", train_ds)\r\nDWTBPM8_encoded = encode_numerical_feature(DWTBPM8, \"DWTBPM8\", train_ds)\r\nDWTBPM9_encoded = encode_numerical_feature(DWTBPM9, \"DWTBPM9\", train_ds)\r\n\r\nall_features = layers.concatenate(\r\n    &#91;\r\n        ECG_encoded,\r\n        GROUP_encoded,\r\n        DWTBPM1_encoded,\r\n        DWTBPM2_encoded,\r\n        DWTBPM3_encoded,\r\n        DWTBPM4_encoded,\r\n        DWTBPM5_encoded,\r\n        DWTBPM6_encoded,\r\n        DWTBPM7_encoded,\r\n        DWTBPM8_encoded,\r\n        DWTBPM9_encoded,\r\n    ]\r\n)\r\nx = layers.Dense(32, activation=\"relu\")(all_features)\r\nx = layers.Dropout(0.5)(x)\r\noutput = layers.Dense(1, activation=\"sigmoid\")(x)\r\nmodel = keras.Model(all_inputs, output)\r\nmodel.compile(\"adam\", \"binary_crossentropy\", metrics=&#91;\"accuracy\"])\r\n\r\n\r\n\r\n\r\n\r\n# `rankdir='LR'` is to make the graph horizontal.\r\nkeras.utils.plot_model(model, show_shapes=True, rankdir=\"LR\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nmodel.fit(train_ds, epochs=50, validation_data=val_ds)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nsample = {\r\n    \"ECG\": 0,\r\n    \"GROUP\":\"T\",\r\n    \"DWTBPM1\": -5.20770,\t\t\t\t\t\t\t\r\n    \"DWTBPM2\": -8.77470,\r\n    \"DWTBPM3\": 6.07780,\r\n    \"DWTBPM4\": 6.33166,\r\n    \"DWTBPM5\": 0.36817,\r\n    \"DWTBPM6\": 0.21152,\r\n    \"DWTBPM7\": 0.13017,\r\n    \"DWTBPM8\": 0.22935,\r\n    \"DWTBPM9\": -1.12358,\r\n    }\r\n\r\ninput_dict = {name: tf.convert_to_tensor(&#91;value]) for name, value in sample.items()}\r\npredictions = model.predict(input_dict)\r\n\r\nprint(\r\n    \"This particular patient had a %.1f percent probability \"\r\n    \"of having a heart disease, as evaluated by our model.\" % (100 * predictions&#91;0]&#91;0],)\r\n\r\n\r\n\r\nsample = {\r\n    \"ECG\": 0,\r\n    \"GROUP\":\"T\",\r\n    \"DWTBPM1\": -5.20770,\t\t\t\t\t\t\t\r\n    \"DWTBPM2\": -8.77470,\r\n    \"DWTBPM3\": 6.07780,\r\n    \"DWTBPM4\": 6.33166,\r\n    \"DWTBPM5\": 0.36817,\r\n    \"DWTBPM6\": 0.21152,\r\n    \"DWTBPM7\": 0.13017,\r\n    \"DWTBPM8\": 0.22935,\r\n    \"DWTBPM9\": -1.12358,\r\n    }\r\n\r\ninput_dict = {name: tf.convert_to_tensor(&#91;value]) for name, value in sample.items()}\r\npredictions = model.predict(input_dict)\r\n\r\nprint(\r\n    \"This particular patient had a %.1f percent probability \"\r\n    \"of having a heart disease, as evaluated by our model.\" % (100 * predictions&#91;0]&#91;0],)\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u039a\u03ce\u03b4\u03b9\u03ba\u03b1\u03c2 \u0391\u03c0\u03bb\u03cc\u03c2<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-85","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/drhack.gr\/index.php?rest_route=\/wp\/v2\/pages\/85","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/drhack.gr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/drhack.gr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/drhack.gr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/drhack.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=85"}],"version-history":[{"count":1,"href":"https:\/\/drhack.gr\/index.php?rest_route=\/wp\/v2\/pages\/85\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/drhack.gr\/index.php?rest_route=\/wp\/v2\/pages\/85\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/drhack.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}