-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mlruns | ||
.ipynb_checkpoints |
66 changes: 66 additions & 0 deletions
66
ML Engineering MLFlow/02. Data Science Workbench/notebooks/mlflow.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# IMPORTING MODULES:\n", | ||
"import mlflow" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"2022/08/22 21:03:52 INFO mlflow.tracking.fluent: Experiment with name 'mlflow_experiments' does not exist. Creating a new experiment.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# RUNNING MLFLOW:\n", | ||
"mlflow.set_experiment(\"mlflow_experiments\")\n", | ||
"with mlflow.start_run():\n", | ||
" mlflow.log_param(\"name\", \"mlflow_test\")\n", | ||
" mlflow.log_param(\"category\", \"algorithm\")\n", | ||
" mlflow.log_param(\"type\", \"classification\")\n", | ||
" for i in range(5):\n", | ||
" mlflow.log_metric(\"i\", i, step=i)\n", | ||
" mlflow.log_artifact(\"mlflow.ipynb\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.10.4 64-bit", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.4" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
10 changes: 10 additions & 0 deletions
10
ML Engineering MLFlow/02. Data Science Workbench/notebooks/randomizer_model/MLmodel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
flavors: | ||
python_function: | ||
cloudpickle_version: 2.1.0 | ||
env: conda.yaml | ||
loader_module: mlflow.pyfunc.model | ||
python_model: python_model.pkl | ||
python_version: 3.10.4 | ||
mlflow_version: 1.26.1 | ||
model_uuid: 02c1b2316ae945da8660d2089dd5dc43 | ||
utc_time_created: '2022-08-27 06:12:05.575524' |
9 changes: 9 additions & 0 deletions
9
ML Engineering MLFlow/02. Data Science Workbench/notebooks/randomizer_model/conda.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python=3.10.4 | ||
- pip<=22.2.1 | ||
- pip: | ||
- mlflow | ||
- cloudpickle==2.1.0 | ||
name: mlflow-env |
7 changes: 7 additions & 0 deletions
7
ML Engineering MLFlow/02. Data Science Workbench/notebooks/randomizer_model/python_env.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
python: 3.10.4 | ||
build_dependencies: | ||
- pip==22.2.1 | ||
- setuptools==58.3.0 | ||
- wheel==0.37.1 | ||
dependencies: | ||
- -r requirements.txt |
Binary file added
BIN
+1.02 KB
ML Engineering MLFlow/02. Data Science Workbench/notebooks/randomizer_model/python_model.pkl
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
ML Engineering MLFlow/02. Data Science Workbench/notebooks/randomizer_model/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mlflow | ||
cloudpickle==2.1.0 |
113 changes: 113 additions & 0 deletions
113
ML Engineering MLFlow/02. Data Science Workbench/notebooks/stockpred.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# IMPORTING MODULES:\n", | ||
"import random\n", | ||
"import mlflow\n", | ||
"import pandas as pd\n", | ||
"from mlflow.pyfunc.model import PythonModel" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# DEFINING THE PYTHON MODEL:\n", | ||
"class RandomPredictor(PythonModel): # Defining the model.\n", | ||
" def __init__(self): # Initializing contructor function.\n", | ||
" pass\n", | ||
"\n", | ||
" def predict(self, context, model_input): # Defining predict function. \n", | ||
" return model_input.apply(lambda x: random.randint(0, 1))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# INITIALIZING AND SAVING THE MODEL:\n", | ||
"model_path = \"randomizer_model\" # Initialization.\n", | ||
"model = RandomPredictor() # Initializing the model.\n", | ||
"mlflow.pyfunc.save_model(path=model_path, python_model=model) # Saving the model. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Model loaded successfully\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# LOADING THE MODEL:\n", | ||
"loaded_model = mlflow.pyfunc.load_model(model_path) # Loading the model.\n", | ||
"print(\"Model loaded successfully\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"2022/08/27 11:57:38 INFO mlflow.tracking.fluent: Experiment with name 'stockpred_experiment' does not exist. Creating a new experiment.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# IMPLEMENTATION OF THE MODEL:\n", | ||
"model_input = pd.DataFrame([range(10)]) # Initializing input example.\n", | ||
"mlflow.set_experiment(\"stockpred_experiment\") # Initializing mlflow experiment.\n", | ||
"with mlflow.start_run():\n", | ||
" model_output = loaded_model.predict(model_input) # Implementation of the model.\n", | ||
" mlflow.log_metric(\"Days Up\", model_output.sum())\n", | ||
" mlflow.log_artifact(\"stockpred.ipynb\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.10.4 64-bit", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.4" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |