From 16a3aa7022849a9852fc3df7c09dd55cc833697e Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Mon, 6 Oct 2025 16:35:53 -0300 Subject: [PATCH] SIENTIAPDE-1231 Update .gitignore, values.yaml, and model_repository.py for improved data handling and logging - Added 'catboost_info/' to .gitignore to prevent tracking of additional temporary files. - Updated GITHUB_BRANCH in values.yaml to reflect the current branch for model retraining. - Enhanced model_repository.py to drop duplicate timestamps in treated data and streamline attribute logging during model retraining. --- .gitignore | 3 +- .../utils/repository/model_repository.py | 32 +++++++++++++------ values.yaml | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index cfaf446..2c8240d 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,5 @@ git_log .env -tmp/ \ No newline at end of file +tmp/ +catboost_info/ \ No newline at end of file diff --git a/laborious/utils/repository/model_repository.py b/laborious/utils/repository/model_repository.py index a58857d..54b1985 100644 --- a/laborious/utils/repository/model_repository.py +++ b/laborious/utils/repository/model_repository.py @@ -709,6 +709,9 @@ class MLFlowRepository(): treated_data = self.detect_and_parse_datetime_index( treated_data, metadata) + treated_data = treated_data.drop_duplicates( + subset=['timestamp'], keep='first') + self.logger.custom_debug( f"Treated data index: {treated_data.index}", metadata) @@ -820,24 +823,33 @@ class MLFlowRepository(): data_model_atributes = vars(data_model) # load class attributes experiment_description = f"Retrain model {model_name} with new data" current_run_name = self.get_next_run_name(experiment) + + attributes = {} + + for name_atribute, val_atribute in pred_model_atributes.items(): + if name_atribute != "model": + attributes[name_atribute] = val_atribute + for name_atribute, val_atribute in data_model_atributes.items(): + if name_atribute != "model": + attributes[name_atribute] = val_atribute + + self.logger.custom_debug( + f"Attributes: {attributes}", metadata) + with mlflow.start_run( run_name=current_run_name, description=experiment_description ) as _run: # update transfomation model # fixed parameters - for name_atribute, val_atribute in pred_model_atributes.items(): - if name_atribute != "model": - mlflow.log_param(name_atribute, val_atribute) - # update prediction model - for name_atribute, val_atribute in data_model_atributes.items(): - if name_atribute != "model": - mlflow.log_param(name_atribute, val_atribute) + for name_atribute, val_atribute in attributes.items(): + mlflow.log_param(name_atribute, val_atribute) + # dynamic parameters, including model itself mlflow.sklearn.log_model(data_model, "data_model") - makedirs("temp", exist_ok=True) + makedirs("tmp/retrain_data", exist_ok=True) - file_path = f"temp/raw_data_{model_name}.csv" + file_path = f"tmp/retrain_data/retrain_data_{model_name}.csv" data.to_csv(file_path, index=True) # log the data raw @@ -1157,7 +1169,7 @@ class MLFlowRepository(): self.logger.custom_info( f"Model experiment created successfully: {experiment}", metadata) - self.logger.custom_info("Performing model retraining", metadata) + self.logger.custom_info("Saving model retrain", metadata) experiment = self.perform_model_retrain( prediction_model, data_model, experiment, model_name, data, metadata) self.logger.custom_info( diff --git a/values.yaml b/values.yaml index ef86d89..c441f65 100644 --- a/values.yaml +++ b/values.yaml @@ -151,7 +151,7 @@ env: - name: GITHUB_REPO_URL value: "git@github.com:Aignosi/sientia-dataops-laborious_temporal.git" - name: GITHUB_BRANCH - value: main + value: SIENTIAPDE-1231-ajustar-o-retreino-do-courier-no-laborious - name: PYTHON_APP value: "laborious.worker.worker"