57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import pandas as pd
|
|
from os import path
|
|
from tensorflow import keras
|
|
from tensorflow.keras import layers
|
|
import sys
|
|
|
|
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
|
|
|
|
if path.exists(model_name):
|
|
model = keras.models.load_model(model_name)
|
|
else:
|
|
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(),
|
|
)
|
|
|
|
history = model.fit(
|
|
X,
|
|
Y,
|
|
batch_size=int(sys.argv[1]),
|
|
epochs=int(sys.argv[2]),
|
|
)
|
|
|
|
model.save(model_name)
|
|
|
|
test_data=pd.read_csv('test.csv')
|
|
X_test=test_data[input_columns].to_numpy()
|
|
Y_test=test_data[["Overall"]].to_numpy()
|
|
|
|
results_train = model.evaluate(X, Y, batch_size=128)
|
|
results_test = model.evaluate(X_test, Y_test, batch_size=128)
|
|
y_pred = model(X_test)
|
|
|
|
lines = ["Name;Overall;Predicted overall\n"]
|
|
for i in range(len(X_test)):
|
|
name = test_data["Name"][i]
|
|
lines.append(f"{name};{int(Y_test[i])};{int(y_pred[i])}\n")
|
|
|
|
with open('results.csv', 'w+', encoding="UTF-8") as f:
|
|
f.writelines(lines)
|
|
|
|
with open('evaluation_result.txt', 'w+', encoding="UTF-8") as f:
|
|
f.write(f"Train: {str(results_train)}\nTest: {str(results_test)}") |