add mlflow
All checks were successful
s464980-evaluation/pipeline/head This commit looks good
s464980-training/pipeline/head This commit looks good

This commit is contained in:
Sheaza 2024-05-14 23:09:01 +02:00
parent 793211467e
commit 98d1c8d505
3 changed files with 13 additions and 7 deletions

View File

@ -17,9 +17,9 @@ predictions = model.predict(X_test)
with open("predictions.txt", "w") as f: with open("predictions.txt", "w") as f:
f.write(str(predictions)) f.write(str(predictions))
accuracy = root_mean_squared_error(y_test, predictions) rmse = root_mean_squared_error(y_test, predictions)
with open("rmse.txt", 'a') as file: with open("rmse.txt", 'a') as file:
file.write(str(accuracy)+"\n") file.write(str(rmse)+"\n")
with open("rmse.txt", 'r') as file: with open("rmse.txt", 'r') as file:
lines = file.readlines() lines = file.readlines()

View File

@ -3,3 +3,4 @@ scikit-learn
tensorflow tensorflow
numpy numpy
matplotlib matplotlib
mlflow

View File

@ -2,7 +2,9 @@ import pandas as pd
from tensorflow import keras from tensorflow import keras
from tensorflow.keras import layers from tensorflow.keras import layers
import argparse import argparse
import mlflow
import mlflow.sklearn
mlflow.set_experiment("s464980")
class RegressionModel: class RegressionModel:
def __init__(self, optimizer="adam", loss="mean_squared_error"): def __init__(self, optimizer="adam", loss="mean_squared_error"):
self.model = keras.Sequential([ self.model = keras.Sequential([
@ -26,7 +28,6 @@ class RegressionModel:
self.y_test = data_test["Performance Index"] self.y_test = data_test["Performance Index"]
def train(self, epochs=30): def train(self, epochs=30):
self.model.compile(optimizer=self.optimizer, loss=self.loss) self.model.compile(optimizer=self.optimizer, loss=self.loss)
self.model.fit(self.X_train, self.y_train, epochs=epochs, batch_size=32, validation_data=(self.X_test, self.y_test)) self.model.fit(self.X_train, self.y_train, epochs=epochs, batch_size=32, validation_data=(self.X_test, self.y_test))
@ -37,6 +38,7 @@ class RegressionModel:
def evaluate(self): def evaluate(self):
test_loss = self.model.evaluate(self.X_test, self.y_test) test_loss = self.model.evaluate(self.X_test, self.y_test)
print(f"Test Loss: {test_loss:.4f}") print(f"Test Loss: {test_loss:.4f}")
return test_loss
def save_model(self): def save_model(self):
self.model.save("model.keras") self.model.save("model.keras")
@ -48,6 +50,9 @@ parser.add_argument('--epochs')
args = parser.parse_args() args = parser.parse_args()
model = RegressionModel() model = RegressionModel()
model.load_data("df_train.csv", "df_test.csv") model.load_data("df_train.csv", "df_test.csv")
with mlflow.start_run() as run:
model.train(epochs=int(args.epochs)) model.train(epochs=int(args.epochs))
model.evaluate() rmse = model.evaluate()
mlflow.log_param("epoch", int(args.epochs))
mlflow.log_metric("rmse", rmse)
model.save_model() model.save_model()