Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo #908

Open
wants to merge 15 commits into
base: demo
Choose a base branch
from
Open

Demo #908

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: 2
version: '2.1'
orbs:
node: circleci/[email protected]

defaults: &defaults
docker:
Expand Down Expand Up @@ -40,15 +42,19 @@ jobs:
command: |
tox

section_07_deploy_app_to_heroku:
section_07_deploy_app_to_railway:
<<: *defaults
steps:
- checkout:
path: ~/project
path: ~/project/
- node/install:
node-version: '16.13'
- run: node --version
- run: npm i -g @railway/cli
- run:
name: Deploy to Heroku
name: Deploy to Railway App (You must set RAILWAY_TOKEN env var)
command: |
git subtree push --prefix section-07-ci-and-publishing/house-prices-api https://heroku:[email protected]/$HEROKU_APP_NAME.git master
cd section-07-ci-and-publishing/house-prices-api && railway up --detach -s splendid-writer -e production

section_07_test_and_upload_regression_model:
<<: *defaults
Expand All @@ -71,28 +77,22 @@ jobs:
tox -e publish_model


section_08_deploy_app_container_in_heroku:
section_08_deploy_app_container_via_railway:
<<: *defaults
steps:
- setup_remote_docker:
# Supported versions: https://circleci.com/docs/2.0/building-docker-images/#docker-version
version: 20.10.6
version: 20.10.18
- checkout:
path: ~/project
path: ~/project/
- node/install:
node-version: '16.13'
- run: node --version
- run: npm i -g @railway/cli
- run:
name: Build image
name: Build and run Dockerfile (see https://docs.railway.app/deploy/dockerfiles)
command: |
sudo curl https://cli-assets.heroku.com/install.sh | sh
cd section-08-deploying-with-containers && make build-ml-api-heroku
- run:
name: Push Image to Heroku
command: |
# Push the built container to the Heroku image registry
cd section-08-deploying-with-containers && make push-ml-api-heroku
- run:
name: Release to Heroku
command: |
cd section-08-deploying-with-containers && make release-heroku
cd section-08-deploying-with-containers && railway up --detach -s splendid-writer -e production

test_regression_model_py37:
docker:
Expand Down Expand Up @@ -265,24 +265,37 @@ tags_only: &tags_only

workflows:
version: 2
section_07:
deploy_pipeline:
jobs:
- section_07_test_app
- section_07_deploy_app_to_heroku:
- section_07_deploy_app_to_railway:
requires:
- section_07_test_app
filters:
branches:
only:
- main
- master
- demo
# upload after git tags are created
- section_07_test_and_upload_regression_model:
<<: *tags_only
- section_08_deploy_app_container_in_heroku:
# <<: *tags_only
requires:
- section_07_deploy_app_to_railway
filters:
branches:
only:
- main
- master
- demo

- section_08_deploy_app_container_via_railway:
filters:
branches:
only:
- main
- master
- demo

# test-all:
# jobs:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
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).


An update.
Original file line number Diff line number Diff line change
Expand Up @@ -4611,8 +4611,8 @@
"source": [
"# Additional Resources\n",
"\n",
"- [Feature Engineering for Machine Learning](https://www.udemy.com/course/feature-engineering-for-machine-learning/?referralCode=A855148E05283015CF06) - Online Course\n",
"- [Packt Feature Engineering Cookbook](https://www.packtpub.com/data/python-feature-engineering-cookbook) - Book\n",
"- [Feature Engineering for Machine Learning](https://www.trainindata.com/p/feature-engineering-for-machine-learning) - Online Course\n",
"- [Packt Feature Engineering Cookbook](https://www.amazon.com/Python-Feature-Engineering-Cookbook-transforming-dp-1804611301/dp/1804611301) - Book\n",
"- [Predict house price with Feature-engine](https://www.kaggle.com/solegalli/predict-house-price-with-feature-engine) - Kaggle kernel\n",
"- [Comprehensive data exploration with Python](https://www.kaggle.com/pmarcelino/comprehensive-data-exploration-with-python) - Kaggle kernel\n",
"- [How I made top 0.3% on a Kaggle competition](https://www.kaggle.com/lavanyashukla01/how-i-made-top-0-3-on-a-kaggle-competition) - Kaggle kernel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@
"\n",
"For the remaining categorical variables, we will group those categories that are present in less than 1% of the observations. That is, all values of categorical variables that are shared by less than 1% of houses, well be replaced by the string \"Rare\".\n",
"\n",
"To learn more about how to handle categorical variables visit our course [Feature Engineering for Machine Learning](https://www.udemy.com/course/feature-engineering-for-machine-learning/?referralCode=A855148E05283015CF06) in Udemy."
"To learn more about how to handle categorical variables visit our course [Feature Engineering for Machine Learning](https://www.trainindata.com/p/feature-engineering-for-machine-learning)."
]
},
{
Expand Down Expand Up @@ -1805,7 +1805,7 @@
"\n",
"We will do it so that we capture the monotonic relationship between the label and the target.\n",
"\n",
"To learn more about how to encode categorical variables visit our course [Feature Engineering for Machine Learning](https://www.udemy.com/course/feature-engineering-for-machine-learning/?referralCode=A855148E05283015CF06) in Udemy."
"To learn more about how to encode categorical variables visit our course [Feature Engineering for Machine Learning](https://www.trainindata.com/p/feature-engineering-for-machine-learning)."
]
},
{
Expand Down Expand Up @@ -3083,9 +3083,9 @@
"\n",
"# Additional Resources\n",
"\n",
"- [Feature Engineering for Machine Learning](https://www.udemy.com/course/feature-engineering-for-machine-learning/?referralCode=A855148E05283015CF06) - Online Course\n",
"- [Packt Feature Engineering Cookbook](https://www.packtpub.com/data/python-feature-engineering-cookbook) - Book\n",
"- [Feature Engineering for Machine Learning: A comprehensive Overview](https://trainindata.medium.com/feature-engineering-for-machine-learning-a-comprehensive-overview-a7ad04c896f8) - Article\n",
"- [Feature Engineering for Machine Learning](https://www.trainindata.com/p/feature-engineering-for-machine-learning) - Online Course\n",
"- [Packt Feature Engineering Cookbook](https://www.amazon.com/Python-Feature-Engineering-Cookbook-transforming-dp-1804611301/dp/1804611301) - Book\n",
"- [Feature Engineering for Machine Learning: A comprehensive Overview](https://www.blog.trainindata.com/feature-engineering-for-machine-learning/) - Article\n",
"- [Practical Code Implementations of Feature Engineering for Machine Learning with Python](https://towardsdatascience.com/practical-code-implementations-of-feature-engineering-for-machine-learning-with-python-f13b953d4bcd) - Article"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,17 @@
"source": [
"# Additional Resources\n",
"\n",
"- [Feature Selection for Machine Learning](https://www.udemy.com/course/feature-selection-for-machine-learning/?referralCode=186501DF5D93F48C4F71) - Online Course\n",
"- [Feature Selection for Machine Learning: A comprehensive Overview](https://trainindata.medium.com/feature-selection-for-machine-learning-a-comprehensive-overview-bd571db5dd2d) - Article"
"- [Feature Selection for Machine Learning](https://www.trainindata.com/p/feature-selection-for-machine-learning) - Online Course\n",
"- [Feature Selection in Machine Learning with Python](https://leanpub.com/feature-selection-in-machine-learning/) - Book\n",
"- [Feature Selection for Machine Learning: A comprehensive Overview](https://www.blog.trainindata.com/feature-selection-for-machine-learning/) - Article"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@
"\n",
"We will do it so that we capture the monotonic relationship between the label and the target.\n",
"\n",
"To learn more about how to encode categorical variables visit our course [Feature Engineering for Machine Learning](https://www.udemy.com/course/feature-engineering-for-machine-learning/?referralCode=A855148E05283015CF06) in Udemy."
"To learn more about how to encode categorical variables visit our course [Feature Engineering for Machine Learning](https://www.trainindata.com/p/feature-engineering-for-machine-learning)."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1095,7 +1095,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.10.5"
},
"toc": {
"base_numbering": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from feature_engine.encoding import OrdinalEncoder, RareLabelEncoder
from feature_engine.imputation import (
AddMissingIndicator,
CategoricalImputer,
MeanMedianImputer,
)
from feature_engine.imputation import AddMissingIndicator, CategoricalImputer, MeanMedianImputer
from feature_engine.selection import DropFeatures
from feature_engine.transformation import LogTransformer
from feature_engine.wrappers import SklearnTransformerWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pydantic>=1.8.1,<2.0.0
scikit-learn>=1.1.3,<2.0.0
strictyaml>=1.3.2,<2.0.0
ruamel.yaml>=0.16.12,<1.0.0
feature-engine>=1.0.2,<2.0.0
feature-engine>=1.0.2,<1.6.0 # breaking change in v1.6.0
joblib>=1.0.1,<2.0.0
3 changes: 1 addition & 2 deletions section-05-production-model-package/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ skipsdist = True
[testenv]
basepython = python
install_command = pip install {opts} {packages}
whitelist_externals = train
allowlist_externals = train

setenv =
PYTHONPATH=.
Expand Down Expand Up @@ -47,7 +47,6 @@ deps =
commands =
flake8 regression_model tests
isort regression_model tests
black regression_model tests
{posargs:mypy regression_model}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pydantic>=1.10.4,<1.12.0
typing_extensions>=4.2.0,<5.0.0
loguru>=0.5.3,<1.0.0
# We will explain this in the course
tid-regression-model>=3.2.0
tid-regression-model>=3.2.0
feature-engine>=1.0.2,<1.6.0 # breaking change in v1.6.0
1 change: 0 additions & 1 deletion section-06-model-serving-api/house-prices-api/runtime.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pydantic>=1.10.4,<1.12.0
typing_extensions>=4.2.0,<5.0.0
loguru>=0.5.3,<1.0.0
# We will explain this in the course
tid-regression-model>=3.2.0
tid-regression-model>=3.2.0
feature-engine>=1.0.2,<1.6.0 # breaking change in v1.6.0
1 change: 0 additions & 1 deletion section-07-ci-and-publishing/house-prices-api/runtime.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.3
4.0.2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Dict, List, Sequence
from typing import Dict, List, Sequence, Optional

from pydantic import BaseModel
from strictyaml import YAML, load
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def make_prediction(
if not errors:
predictions = _price_pipe.predict(
X=validated_data[config.model_config.features]
)
)
dtype = np.result_type(np.float32, predictions)
results = {
"predictions": [np.exp(pred) for pred in predictions], # type: ignore
"predictions": [np.exp(pred).astype(dtype) for pred in predictions], # type: ignore
"version": _version,
"errors": errors,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pydantic>=1.8.1,<2.0.0
scikit-learn>=1.1.3,<2.0.0
strictyaml>=1.3.2,<2.0.0
ruamel.yaml>=0.16.12,<1.0.0
feature-engine>=1.0.2,<2.0.0
feature-engine>=1.0.2,<1.6.0 # breaking change in v1.6.0
joblib>=1.0.1,<2.0.0
8 changes: 6 additions & 2 deletions section-07-ci-and-publishing/model-package/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ skipsdist = True
[testenv]
basepython = python
install_command = pip install {opts} {packages}
whitelist_externals = train
allowlist_externals = train,python

passenv =
KAGGLE_USERNAME
KAGGLE_KEY
GEMFURY_PUSH_URL
RAILWAY_TOKEN

[testenv:test_package]
allowlist_externals = python
deps =
-rrequirements/test_requirements.txt

Expand Down Expand Up @@ -50,8 +52,9 @@ commands=

[testenv:fetch_data]
envdir = {toxworkdir}/test_package
allowlist_externals = unzip
deps =
{[testenv:test_package]deps}
kaggle<1.6.0

setenv =
{[testenv:test_package]setenv}
Expand All @@ -65,6 +68,7 @@ commands=

[testenv:publish_model]
envdir = {toxworkdir}/test_package
allowlist_externals = *
deps =
{[testenv:test_package]deps}

Expand Down
13 changes: 0 additions & 13 deletions section-08-deploying-with-containers/Makefile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pydantic>=1.10.4,<1.12.0
typing_extensions>=4.2.0,<5.0.0
loguru>=0.5.3,<1.0.0
# fetched from gemfury
tid-regression-model==4.0.2
tid-regression-model==4.0.5
feature-engine>=1.0.2,<1.6.0 # breaking change in v1.6.0

This file was deleted.