Skip to content

Commit

Permalink
Added Notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinamXx committed Aug 27, 2022
1 parent 05a35d8 commit 44be108
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ML Engineering MLFlow/02. Data Science Workbench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mlruns
.ipynb_checkpoints
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
}
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'
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
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 not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mlflow
cloudpickle==2.1.0
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
}

0 comments on commit 44be108

Please sign in to comment.