forked from Azure/azureml-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update monitoring samples (Azure#2970)
* update monitoring samples * remove sensitive information, make general for the public * reformat python * small changes * small change data column names * missed one
- Loading branch information
1 parent
7346ebe
commit 2d22516
Showing
15 changed files
with
1,591 additions
and
82 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
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
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,138 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Other | ||
.vscode | ||
.DS_Store | ||
.amlignore | ||
*.amltmp | ||
notebooks/.ipynb_checkpoints/ | ||
data/reference | ||
data/production |
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 @@ | ||
# AzureML E2E Model Monitoring | ||
|
||
In this sample notebook, you will observe the end-to-end lifecycle of the Machine Learning (ML) operationalization process. You will follow the following steps to train your ML model, deploy it to production, and monitor it to ensure its continuous performance: | ||
|
||
1) Setup environment | ||
2) Register data assets | ||
3) Train the model | ||
4) Deploy the model | ||
5) Simulate inference requests | ||
6) Monitor the model |
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,98 @@ | ||
"""Script for an azureml online deployment""" | ||
import json | ||
import logging | ||
import os | ||
import uuid | ||
from typing import Dict, List | ||
|
||
import mlflow | ||
import pandas as pd | ||
from azureml.ai.monitoring import Collector | ||
from inference_schema.parameter_types.standard_py_parameter_type import ( | ||
StandardPythonParameterType, | ||
) | ||
from inference_schema.schema_decorators import input_schema, output_schema | ||
|
||
# define global variables | ||
MODEL = None | ||
INPUTS_COLLECTOR = None | ||
OUTPUTS_COLLECTOR = None | ||
INPUTS_OUTPUTS_COLLECTOR = None | ||
|
||
INPUT_SAMPLE = [ | ||
{ | ||
"LIMIT_BAL": 20000, | ||
"SEX": 2, | ||
"EDUCATION": 2, | ||
"MARRIAGE": 1, | ||
"AGE": 24, | ||
"PAY_0": 2, | ||
"PAY_2": 2, | ||
"PAY_3": -1, | ||
"PAY_4": -1, | ||
"PAY_5": -2, | ||
"PAY_6": -2, | ||
"BILL_AMT1": 3913, | ||
"BILL_AMT2": 3102, | ||
"BILL_AMT3": 689, | ||
"BILL_AMT4": 0, | ||
"BILL_AMT5": 0, | ||
"BILL_AMT6": 0, | ||
"PAY_AMT1": 0, | ||
"PAY_AMT2": 689, | ||
"PAY_AMT3": 0, | ||
"PAY_AMT4": 0, | ||
"PAY_AMT5": 0, | ||
"PAY_AMT6": 0, | ||
} | ||
] | ||
|
||
# define sample response for inference | ||
OUTPUT_SAMPLE = {"DEFAULT_NEXT_MONTH": [0]} | ||
|
||
|
||
def init() -> None: | ||
"""Startup event handler to load an MLFLow model.""" | ||
global MODEL, INPUTS_COLLECTOR, OUTPUTS_COLLECTOR, INPUTS_OUTPUTS_COLLECTOR | ||
|
||
# instantiate collectors | ||
INPUTS_COLLECTOR = Collector(name="model_inputs") | ||
OUTPUTS_COLLECTOR = Collector(name="model_outputs") | ||
INPUTS_OUTPUTS_COLLECTOR = Collector(name="model_inputs_outputs") | ||
|
||
# Load MLFlow model | ||
MODEL = mlflow.sklearn.load_model(os.getenv("AZUREML_MODEL_DIR") + "/model_output") | ||
|
||
|
||
@input_schema("data", StandardPythonParameterType(INPUT_SAMPLE)) | ||
@output_schema(StandardPythonParameterType(OUTPUT_SAMPLE)) | ||
def run(data: List[Dict]) -> str: | ||
"""Perform scoring for every invocation of the endpoint""" | ||
|
||
# Append datetime column to predictions | ||
input_df = pd.DataFrame(data) | ||
|
||
# Preprocess payload and get model prediction | ||
model_output = MODEL.predict(input_df).tolist() | ||
output_df = pd.DataFrame(model_output, columns=["DEFAULT_NEXT_MONTH"]) | ||
|
||
# Make response payload | ||
response_payload = json.dumps({"DEFAULT_NEXT_MONTH": model_output}) | ||
|
||
# --- Azure ML Data Collection --- | ||
|
||
# collect inputs data | ||
context = INPUTS_COLLECTOR.collect(input_df) | ||
|
||
# collect outputs data | ||
OUTPUTS_COLLECTOR.collect(output_df, context) | ||
|
||
# create a dataframe with inputs/outputs joined - this creates a URI folder (not mltable) | ||
input_output_df = input_df.join(output_df) | ||
|
||
# collect both your inputs and output | ||
INPUTS_OUTPUTS_COLLECTOR.collect(input_output_df, context) | ||
|
||
# ---------------------------------- | ||
|
||
return response_payload |
Oops, something went wrong.