ium_495719/create_model.py

39 lines
1.3 KiB
Python
Raw Normal View History

2024-04-27 18:00:53 +02:00
import pandas as pd
2024-05-14 15:32:43 +02:00
import sys
2024-04-27 18:00:53 +02:00
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam
from keras import regularizers
2024-05-16 03:01:35 +02:00
import mlflow
2024-04-27 18:00:53 +02:00
from helper import prepare_tensors
2024-05-14 15:32:43 +02:00
epochs = int(sys.argv[1])
2024-05-16 03:01:35 +02:00
learning_rate = float(sys.argv[2])
batch_size = int(sys.argv[3])
2024-05-14 15:32:43 +02:00
2024-04-27 18:00:53 +02:00
hp_train = pd.read_csv('hp_train.csv')
hp_dev = pd.read_csv('hp_dev.csv')
X_train, Y_train = prepare_tensors(hp_train)
X_dev, Y_dev = prepare_tensors(hp_dev)
model = Sequential()
model.add(Dense(64, input_dim=7, activation='relu', kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(32, activation='relu', kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(16, activation='relu', kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(8, activation='relu', kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(1, activation='linear'))
2024-05-16 03:01:35 +02:00
adam = Adam(learning_rate=learning_rate, beta_1=0.9, beta_2=0.999, epsilon=1e-7)
2024-04-27 18:00:53 +02:00
model.compile(optimizer=adam, loss='mean_squared_error')
2024-05-16 03:01:35 +02:00
model.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, validation_data=(X_dev, Y_dev))
2024-04-27 18:00:53 +02:00
model.save('hp_model.h5')
2024-05-16 03:01:35 +02:00
with mlflow.start_run() as run:
mlflow.log_param("epochs", epochs)
mlflow.log_param("learning_rate", learning_rate)
mlflow.log_param("batch_size", batch_size)