ium_434760/train.py

48 lines
1.3 KiB
Python
Raw Normal View History

2021-04-25 17:39:38 +02:00
import pandas as pd
from os import path
from tensorflow import keras
from tensorflow.keras import layers
2021-05-16 23:41:55 +02:00
import mlflow
2021-04-28 21:21:14 +02:00
import sys
2021-04-25 17:39:38 +02:00
model_name = "model.h5"
train_data=pd.read_csv('train.csv')
input_columns=["Age","Nationality","Position","Club"]
X=train_data[input_columns].to_numpy()
Y=train_data[["Overall"]].to_numpy()
model = None
2021-04-30 00:07:34 +02:00
model = keras.Sequential(name="fifa_overall")
model.add(keras.Input(shape=(len(input_columns),), name="player_info"))
model.add(layers.Dense(4, activation="relu", name="layer1"))
model.add(layers.Dense(8, activation="relu", name="layer2"))
model.add(layers.Dense(8, activation="relu", name="layer3"))
model.add(layers.Dense(5, activation="relu", name="layer4"))
model.add(layers.Dense(1, activation="relu", name="output"))
model.compile(
optimizer=keras.optimizers.RMSprop(),
loss=keras.losses.MeanSquaredError(),
)
2021-05-16 23:41:55 +02:00
batch_size = int(sys.argv[1])
epochs = int(sys.argv[2])
mlflow.log_param("batch_size", batch_size)
mlflow.log_param("epochs", epochs)
2021-04-30 00:07:34 +02:00
history = model.fit(
X,
Y,
2021-05-16 23:41:55 +02:00
batch_size=batch_size,
epochs=epochs,
2021-04-30 00:07:34 +02:00
)
2021-05-24 00:52:24 +02:00
model.save(model_name)
signature = mlflow.models.signature.infer_signature(X, model.predict(X))
input_example = {
"Age": 0.38,
"Nationality": 0.175,
"Position": 1,
"Club" :0.91846154
}
mlflow.keras.save_model(model, "fifa_overall", signature=signature, input_example = input_example)