Skip to content

Commit 622eeca

Browse files
committed
momo - adding section on model performance monitoring
1 parent a31214a commit 622eeca

File tree

1 file changed

+217
-0
lines changed

1 file changed

+217
-0
lines changed

articles/machine-learning/how-to-monitor-model-performance.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,223 @@ created_monitor = poller.result()
478478

479479
---
480480

481+
## Set up model performance monitoring
482+
483+
Azure Machine Learning model monitoring enables you to track the objective performance of your models in production by calculating model performance metrics. These model performance metrics include accuracy (for classification models) and root mean squared error (RMSE) for (regression models).
484+
485+
Before you can configure your model performance signal, you need to satisfy the following requirements:
486+
487+
* Have production model output data (your model's predictions) with a unique ID for each row.
488+
* Have ground truth data (or actuals) with a unique ID for each row. This data will be joined with production data.
489+
* (Optional) Have a prejoined dataset with model outputs and ground truth data.
490+
491+
The key requirement for enabling model performance monitoring is that you already collected ground truth data. Since ground truth data is encountered at the application level, it's your responsibility to collect it as it becomes available. You should also maintain a data asset in Azure Machine Learning with this ground truth data.
492+
493+
To illustrate, suppose you have a deployed model to predict if a credit card transaction is fraudulent or not fraudulent. As you use this model in production, you can collect the model output data with the [model data collector](how-to-collect-production-data.md). Ground truth data becomes available when a credit card holder specifies whether or not the transaction was fraudulent or not. This `is_fraud` ground truth should be collected at the application level and maintained within an Azure Machine Learning data asset that the model performance monitoring signal can use.
494+
495+
# [Azure CLI](#tab/azure-cli)
496+
497+
Once you've satisfied the previous requirements, you can set up model monitoring with the following CLI command and YAML definition:
498+
499+
```azurecli
500+
az ml schedule create -f ./model-performance-monitoring.yaml
501+
```
502+
503+
The following YAML contains the definition for model monitoring with production inference data that you've collected.
504+
505+
```YAML
506+
$schema: http://azureml/sdk-2-0/Schedule.json
507+
name: model_performance_monitoring
508+
display_name: Credit card fraud model performance
509+
description: Credit card fraud model performance
510+
511+
trigger:
512+
type: recurrence
513+
frequency: day
514+
interval: 7
515+
schedule:
516+
hours: 10
517+
minutes: 15
518+
519+
create_monitor:
520+
compute:
521+
instance_type: standard_e8s_v3
522+
runtime_version: "3.3"
523+
monitoring_target:
524+
ml_task: classification
525+
endpoint_deployment_id: azureml:loan-approval-endpoint:loan-approval-deployment
526+
527+
monitoring_signals:
528+
fraud_detection_model_performance:
529+
type: model_performance
530+
production_data:
531+
data_column_names:
532+
prediction: is_fraud
533+
correlation_id: correlation_id
534+
reference_data:
535+
input_data:
536+
path: azureml:my_model_ground_truth_data:1
537+
type: mltable
538+
data_column_names:
539+
actual: is_fraud
540+
correlation_id: correlation_id
541+
data_context: actuals
542+
alert_enabled: true
543+
metric_thresholds:
544+
tabular_classification:
545+
accuracy: 0.95
546+
precision: 0.8
547+
alert_notification:
548+
emails:
549+
550+
```
551+
552+
# [Python SDK](#tab/python)
553+
554+
Once you've satisfied the previous requirements, you can set up model monitoring using the following Python code:
555+
556+
```python
557+
from azure.identity import InteractiveBrowserCredential
558+
from azure.ai.ml import Input, MLClient
559+
from azure.ai.ml.constants import (
560+
MonitorFeatureType,
561+
MonitorMetricName,
562+
MonitorDatasetContext
563+
)
564+
from azure.ai.ml.entities import (
565+
AlertNotification,
566+
DataDriftSignal,
567+
DataQualitySignal,
568+
DataDriftMetricThreshold,
569+
DataQualityMetricThreshold,
570+
NumericalDriftMetrics,
571+
CategoricalDriftMetrics,
572+
DataQualityMetricsNumerical,
573+
DataQualityMetricsCategorical,
574+
MonitorFeatureFilter,
575+
MonitorInputData,
576+
MonitoringTarget,
577+
MonitorDefinition,
578+
MonitorSchedule,
579+
RecurrencePattern,
580+
RecurrenceTrigger,
581+
ServerlessSparkCompute,
582+
ReferenceData,
583+
ProductionData
584+
)
585+
586+
# get a handle to the workspace
587+
ml_client = MLClient(
588+
InteractiveBrowserCredential(),
589+
subscription_id,
590+
resource_group,
591+
workspace
592+
)
593+
594+
spark_compute = ServerlessSparkCompute(
595+
instance_type="standard_e4s_v3",
596+
runtime_version="3.2"
597+
)
598+
599+
#define target dataset (production dataset)
600+
production_data = ProductionData(
601+
input_data=Input(
602+
type="uri_folder",
603+
path="azureml:my_model_production_data:1"
604+
),
605+
data_context=MonitorDatasetContext.MODEL_INPUTS,
606+
pre_processing_component="azureml:production_data_preprocessing:1"
607+
)
608+
609+
610+
# training data to be used as baseline dataset
611+
reference_data_training = ReferenceData(
612+
input_data=Input(
613+
type="mltable",
614+
path="azureml:my_model_training_data:1"
615+
),
616+
data_context=MonitorDatasetContext.TRAINING
617+
)
618+
619+
# create an advanced data drift signal
620+
features = MonitorFeatureFilter(top_n_feature_importance=20)
621+
metric_thresholds = DataDriftMetricThreshold(
622+
numerical=NumericalDriftMetrics(
623+
jensen_shannon_distance=0.01
624+
),
625+
categorical=CategoricalDriftMetrics(
626+
pearsons_chi_squared_test=0.02
627+
)
628+
)
629+
630+
advanced_data_drift = DataDriftSignal(
631+
production_data=production_data,
632+
reference_data=reference_data_training,
633+
features=features,
634+
metric_thresholds=metric_thresholds
635+
)
636+
637+
638+
# create an advanced data quality signal
639+
features = ['feature_A', 'feature_B', 'feature_C']
640+
metric_thresholds = DataQualityMetricThreshold(
641+
numerical=DataQualityMetricsNumerical(
642+
null_value_rate=0.01
643+
),
644+
categorical=DataQualityMetricsCategorical(
645+
out_of_bounds_rate=0.02
646+
)
647+
)
648+
649+
advanced_data_quality = DataQualitySignal(
650+
production_data=production_data,
651+
reference_data=reference_data_training,
652+
features=features,
653+
metric_thresholds=metric_thresholds,
654+
alert_enabled="False"
655+
)
656+
657+
# put all monitoring signals in a dictionary
658+
monitoring_signals = {
659+
'data_drift_advanced': advanced_data_drift,
660+
'data_quality_advanced': advanced_data_quality
661+
}
662+
663+
# create alert notification object
664+
alert_notification = AlertNotification(
665+
666+
)
667+
668+
# Finally monitor definition
669+
monitor_definition = MonitorDefinition(
670+
compute=spark_compute,
671+
monitoring_signals=monitoring_signals,
672+
alert_notification=alert_notification
673+
)
674+
675+
recurrence_trigger = RecurrenceTrigger(
676+
frequency="day",
677+
interval=1,
678+
schedule=RecurrencePattern(hours=3, minutes=15)
679+
)
680+
681+
model_monitor = MonitorSchedule(
682+
name="fraud_detection_model_monitoring_advanced",
683+
trigger=recurrence_trigger,
684+
create_monitor=monitor_definition
685+
)
686+
687+
poller = ml_client.schedules.begin_create_or_update(model_monitor)
688+
created_monitor = poller.result()
689+
690+
```
691+
692+
# [Studio](#tab/azure-studio)
693+
694+
The studio currently doesn't support model performance monitoring.
695+
696+
---
697+
481698
## Set up model monitoring by bringing your own production data to Azure Machine Learning
482699

483700
You can also set up model monitoring for models deployed to Azure Machine Learning batch endpoints or deployed outside of Azure Machine Learning. If you have production data but no deployment, you can use the data to perform continuous model monitoring. To monitor these models, you must meet the following requirements:

0 commit comments

Comments
 (0)