From c5abfac0ad38e204fca2e5cd00308a6e45302135 Mon Sep 17 00:00:00 2001 From: "Zhu Runzhe(Morgan)" Date: Mon, 5 Feb 2024 16:24:41 +0800 Subject: [PATCH 1/5] update: lines 57 and 95 in CircleCI config --- .circleci/config.yml | 4 +-- .../trained_models/train_pipeline.py | 30 +++++++++++++++++++ .../requirements/requirements.txt | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 section-05-production-model-package/regression_model/trained_models/train_pipeline.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 037645ab2..393468a98 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -54,7 +54,7 @@ jobs: - run: name: Deploy to Railway App (You must set RAILWAY_TOKEN env var) command: | - cd section-07-ci-and-publishing/house-prices-api && railway up --detach + cd section-07-ci-and-publishing/house-prices-api && railway up --detach -s MLDevOps-Beginner -e production section_07_test_and_upload_regression_model: <<: *defaults @@ -92,7 +92,7 @@ jobs: - run: name: Build and run Dockerfile (see https://docs.railway.app/deploy/dockerfiles) command: | - cd section-08-deploying-with-containers && railway up --detach + cd section-08-deploying-with-containers && railway up --detach -s MLDevOps-Beginner -e production test_regression_model_py37: docker: diff --git a/section-05-production-model-package/regression_model/trained_models/train_pipeline.py b/section-05-production-model-package/regression_model/trained_models/train_pipeline.py new file mode 100644 index 000000000..edcdd7c15 --- /dev/null +++ b/section-05-production-model-package/regression_model/trained_models/train_pipeline.py @@ -0,0 +1,30 @@ +import numpy as np +from config.core import config +from pipeline import price_pipe +from processing.data_manager import load_dataset, save_pipeline +from sklearn.model_selection import train_test_split + +def run_training() -> None: + """Train the model""" + + # read training data + data = load_dataset(file_name=config.app_config.training_data_file) + + # divide train and test + X_train, X_test, y_train, y_test = train_test_split( + data[config.model_config.features], # predictors + data[config.model_config.target], + test_size=config.model_config.test_size, + # we are setting the random seed here for reproductivity + random_state=config.model_config.random_state, + ) + y_train= np.log(y_train) + + # fit model + price_pipe.fit(X_train, y_train) + + # persist trained model + save_pipeline(pipeline_to_persist=price_pipe) + +if __name__ == "__main__": + run_training() \ No newline at end of file diff --git a/section-05-production-model-package/requirements/requirements.txt b/section-05-production-model-package/requirements/requirements.txt index 0fbffd3a6..607a23ff0 100644 --- a/section-05-production-model-package/requirements/requirements.txt +++ b/section-05-production-model-package/requirements/requirements.txt @@ -1,7 +1,7 @@ # We use compatible release functionality (see PEP 440 here: https://www.python.org/dev/peps/pep-0440/#compatible-release) # to specify acceptable version ranges of our project dependencies. This gives us the flexibility to keep up with small # updates/fixes, whilst ensuring we don't install a major update which could introduce backwards incompatible changes. -numpy>=1.21.0,<2.0.0 +numpy>=1.21.0,<1.24.9 #2.0.0 pandas>=1.3.5,<2.0.0 pydantic>=1.8.1,<2.0.0 scikit-learn>=1.1.3,<2.0.0 From a1f9583b464b5b0f7f328904e50a080e2973fac8 Mon Sep 17 00:00:00 2001 From: "Zhu Runzhe(Morgan)" Date: Tue, 6 Feb 2024 14:47:58 +0800 Subject: [PATCH 2/5] update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7fbf80b75..7144ee044 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ Accompanying repo for the online course Deployment of Machine Learning Models. For the documentation, visit the [course on Udemy](https://www.udemy.com/deployment-of-machine-learning-models/?couponCode=TIDREPO). + +update: to text CI/ CD pipeline \ No newline at end of file From b81172bb5d6eb1fbbfa6a092aeeffb0dc280c67c Mon Sep 17 00:00:00 2001 From: "Zhu Runzhe(Morgan)" Date: Tue, 6 Feb 2024 15:06:15 +0800 Subject: [PATCH 3/5] change README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7144ee044..bb7935a94 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ Accompanying repo for the online course Deployment of Machine Learning Models. For the documentation, visit the [course on Udemy](https://www.udemy.com/deployment-of-machine-learning-models/?couponCode=TIDREPO). -update: to text CI/ CD pipeline \ No newline at end of file +update: only for testing CI/ CD pipeline \ No newline at end of file From cffd66f984ef41aab2f7d67d0daa8e3537f4a32f Mon Sep 17 00:00:00 2001 From: "Zhu Runzhe(Morgan)" Date: Wed, 7 Feb 2024 10:55:15 +0800 Subject: [PATCH 4/5] change line 72 core.py under section 07: Path -> Optional[Path] --- .../model-package/regression_model/config/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/section-07-ci-and-publishing/model-package/regression_model/config/core.py b/section-07-ci-and-publishing/model-package/regression_model/config/core.py index f5f354b19..d64798d59 100644 --- a/section-07-ci-and-publishing/model-package/regression_model/config/core.py +++ b/section-07-ci-and-publishing/model-package/regression_model/config/core.py @@ -69,7 +69,7 @@ def find_config_file() -> Path: raise Exception(f"Config not found at {CONFIG_FILE_PATH!r}") -def fetch_config_from_yaml(cfg_path: Path = None) -> YAML: +def fetch_config_from_yaml(cfg_path: Optional[Path] = None) -> YAML: """Parse YAML containing the package configuration.""" if not cfg_path: From aee260c2a08dfe3d6e39122da5b0d61b95b3559d Mon Sep 17 00:00:00 2001 From: "Zhu Runzhe(Morgan)" Date: Wed, 7 Feb 2024 11:13:00 +0800 Subject: [PATCH 5/5] import Optional on line 2 core.py under section 07 --- .../model-package/regression_model/config/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/section-07-ci-and-publishing/model-package/regression_model/config/core.py b/section-07-ci-and-publishing/model-package/regression_model/config/core.py index d64798d59..f321864f9 100644 --- a/section-07-ci-and-publishing/model-package/regression_model/config/core.py +++ b/section-07-ci-and-publishing/model-package/regression_model/config/core.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Dict, List, Sequence +from typing import Dict, List, Optional, Sequence from pydantic import BaseModel from strictyaml import YAML, load