ium_470607/lab5/train/train.py

34 lines
953 B
Python
Raw Normal View History

2021-05-02 22:01:32 +02:00
import pandas as pd
2021-05-15 17:34:13 +02:00
import sys
2021-05-15 19:01:47 +02:00
import tensorflow
2021-05-02 22:01:32 +02:00
from tensorflow.keras import layers
X_train = pd.read_csv('train.csv')
X_test = pd.read_csv('test.csv')
2021-05-14 21:52:14 +02:00
X_valid = pd.read_csv('valid.csv')
2021-05-02 22:01:32 +02:00
Y_train = X_train.pop('stabf')
2021-05-14 21:52:14 +02:00
Y_train = pd.get_dummies(Y_train)
2021-05-02 22:01:32 +02:00
2021-05-14 21:52:14 +02:00
Y_test = X_test.pop('stabf')
Y_test = pd.get_dummies(Y_test)
2021-05-02 22:01:32 +02:00
2021-05-14 21:52:14 +02:00
Y_valid = X_valid.pop('stabf')
Y_valid = pd.get_dummies(Y_valid)
2021-05-02 22:01:32 +02:00
2021-05-15 19:01:47 +02:00
model = tensorflow.keras.Sequential([
2021-05-15 21:50:50 +02:00
layers.Input(shape=(12,)),
2021-05-02 22:01:32 +02:00
layers.Dense(32),
layers.Dense(16),
2021-05-14 21:52:14 +02:00
layers.Dense(2, activation='softmax')
])
2021-05-02 22:01:32 +02:00
model.compile(
2021-05-15 19:01:47 +02:00
loss=tensorflow.keras.losses.BinaryCrossentropy(),
optimizer=tensorflow.keras.optimizers.Adam(lr=float(sys.argv[1])),
metrics=[tensorflow.keras.metrics.BinaryAccuracy()])
2021-05-02 22:01:32 +02:00
2021-05-15 19:17:28 +02:00
history = model.fit(X_train, Y_train, epochs=2, validation_data=(X_valid, Y_valid))
2021-05-14 21:52:14 +02:00
model.save('grid-stability-dense.h5')