From 9d66acbdad756b441f7d465c3478a1689c9614a0 Mon Sep 17 00:00:00 2001 From: zgolebiewska Date: Sun, 26 May 2024 14:16:50 +0200 Subject: [PATCH] IUM_08 --- PMProject.yaml | 14 ++++++++++++++ conda.yaml | 10 ++++++++++ model.py | 21 ++++++++++++++++----- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 PMProject.yaml create mode 100644 conda.yaml diff --git a/PMProject.yaml b/PMProject.yaml new file mode 100644 index 0000000..0ed480e --- /dev/null +++ b/PMProject.yaml @@ -0,0 +1,14 @@ +name: OrangeQualityModel + +conda_env: conda.yaml + +entry_points: + train: + parameters: + epochs: {type: int, default: 100} + command: "python model.py" + + test: + parameters: + model_path: {type: str, default: "orange_quality_model_tf.h5"} + command: "python test_model.py --model_path {model_path}" diff --git a/conda.yaml b/conda.yaml new file mode 100644 index 0000000..f759448 --- /dev/null +++ b/conda.yaml @@ -0,0 +1,10 @@ +name: orange_quality_model_env +channels: + - defaults +dependencies: + - python=3.8 + - pip + - pandas + - scikit-learn + - tensorflow + - mlflow \ No newline at end of file diff --git a/model.py b/model.py index efa1509..f1633c8 100644 --- a/model.py +++ b/model.py @@ -3,6 +3,9 @@ import pandas as pd from sklearn.preprocessing import LabelEncoder, StandardScaler from sklearn.model_selection import train_test_split import json +import mlflow + +mlflow.set_tracking_uri("http://localhost:5000") # Ustawienie adresu MLflow Tracking Server df = pd.read_csv('OrangeQualityData.csv') @@ -30,11 +33,19 @@ model = tf.keras.Sequential([ model.compile(optimizer='sgd', loss='mse') -history = model.fit(X_train_scaled, y_train, epochs=100, verbose=0, validation_data=(X_test_scaled, y_test)) +with mlflow.start_run(): + mlflow.log_param("optimizer", 'sgd') + mlflow.log_param("loss_function", 'mse') + mlflow.log_param("epochs", 100) -model.save('orange_quality_model_tf.h5') + history = model.fit(X_train_scaled, y_train, epochs=100, verbose=0, validation_data=(X_test_scaled, y_test)) -predictions = model.predict(X_test_scaled) + for key, value in history.history.items(): + mlflow.log_metric(key, value[-1]) # Logujemy ostatnią wartość metryki -with open('predictions_tf.json', 'w') as f: - json.dump(predictions.tolist(), f, indent=4) + model.save('orange_quality_model_tf.h5') + + predictions = model.predict(X_test_scaled) + + with open('predictions_tf.json', 'w') as f: + json.dump(predictions.tolist(), f, indent=4)