-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (51 loc) · 1.71 KB
/
main.py
File metadata and controls
63 lines (51 loc) · 1.71 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import tensorflow as tf
import numpy as np
import pandas as pd
from pathlib import Path
root = Path(__file__).parent
#load csv
def transform_categorical(df, stop_overfit = False):
CATEGORICAL_COLUMNS = ['work_type']
for original_column in CATEGORICAL_COLUMNS:
df_to_add = pd.get_dummies(df[original_column])
colnames = df_to_add.columns.values
for i in colnames:
if stop_overfit and i == colnames[-1]:
break
df[i] = df_to_add[i].tolist() #add new col
df.drop([original_column], axis = 1, inplace=True) #remove original col
return df
def get_csv(csv='participants_dataset.csv'):
'''get csv from file an turn into a numpy array'''
dt = pd.read_csv(str(root/csv))
dt.drop(['ID'
]
, axis=1, inplace=True)
dt = transform_categorical(dt)
#remove rows without label
return dt
dt = get_csv()
dt = dt.dropna()
dt = dt[dt['avg_glucose_level'] < 265]
features = dt.copy()
labels = features.pop('label')
features = np.array(features).astype('float32')
model_path = str(root / 'model')
if __name__ == "__main__":
normalize = tf.keras.layers.Normalization()
normalize.adapt(features)
model = tf.keras.Sequential([
normalize,
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(1),
])
model.compile(loss = tf.keras.losses.MeanSquaredError(),
optimizer = tf.keras.optimizers.Adam())
model.fit(x = features, y = labels, epochs=50)
model.save(model_path)