Skip to content

SPC drift config

All models that create a SpcDriftProfile will require a SpcDriftConfig object.

from scouter.alert import SpcAlertConfig
from scouter.drift import SpcDriftConfig
SpcDriftConfig(
name="wine_model",
space="wine_model",
version="0.0.1",
alert_config=SpcAlertConfig(),
sample_size=1000
)
ParameterTypeDescriptionExample
namestrThe name of the model or dataset being monitored. Defaults to ‘__missing__’ if not provided.config.name → "wine_model"
spacestrThe space where the model or dataset is stored. Defaults to ‘__missing__’ if not provided.config.space → "wine_model"
versionstrThe version of the model or dataset being monitored. Defaults to ‘0.0.1’ if not provided.config.version → "0.0.1"
alert_configSpcAlertConfigConfiguration for alerting when drift is detected. Defaults to the default implementation of SpcAlertConfig if not provided.config.alert_config → *Instance of SpcAlertConfig*
targetslist[str]List of target features, typically the dependent variable(s).config.targets → ["churn"]
config_pathOptional[Path]Path to a pre existing SpcDriftConfig. Defaults to None if not providedconfig.config_path → Path("/configs/drift.yaml")
sampleboolSpecifies whether sampling should be applied when calculating SPC metrics. Defaults to True.config.sample → True
sample_sizeintDefines the number of data points to include in the sample when sampling is enabled for SPC metric computation. Defaults to 25config.sample → True
PropertyTypeDescriptionExample
namestrThe name of the model or dataset being monitored.config.name"wine_model"
spacestrThe space where the model or dataset is stored.config.space"wine_model"
versionstrThe version of the model or dataset being monitored.config.version"0.0.1"
feature_mapFeatureMapWhen a non-numeric covariate is detected, each unique value is assigned a corresponding numeric value. This mapping is represented by feature_map.config.feature_mapInstance of FeatureMap
targetslist[str]List of target features, typically the dependent variable(s).config.targetslabel
alert_configSpclertConfigConfiguration for alerting when drift is detected.config.alert_configInstance of SpcAlertConfig
drift_typeDriftTypeType of drift profile.config.drift_typeDriftType.Spc
sample_sizeintDefines the number of data points to include in the sample when sampling is enabled for SPC metric computation.config.sample_size1000
sampleboolSpecifies whether sampling should be applied when calculating SPC metrics.config.sampleTrue

Loads a SpcDriftConfig instance from a JSON file.

  • Parameters:
    • path (Path): The path to the JSON configuration file. This is required to locate and read the configuration file from disk.
  • Returns: A SpcDriftConfig instance.
  • Return Type: SpcDriftConfig

Serializes the SpcDriftConfig instance to a JSON string.

  • Parameters: None
  • Returns: A JSON string representation of the instance.
  • Return Type: str

Updates the configuration of the instance with new values.

  • Parameters:
    • space (Optional[str]): The space name, if updating.
    • name (Optional[str]): The new name for the configuration, if provided.
    • version (Optional[str]): The version to set, if specified.
    • targets (Optional[List[str]]): A list of target identifiers, if updating.
    • alert_config (Optional[SpcAlertConfig]): The alert configuration, if provided.
    • sample (Optional[bool]): Opt in or out of the sampling strategy.
    • sample_size (Optional[int]): Adjust the sample size.
  • Returns: None
  • Return Type: None

An AlertConfig can also be provided to the SpcDriftConfig to specify how you and your team want to be alerted in the event of model drift. The SpcAlertConfig class allows you to configure the alerting mechanism, including the dispatch method (e.g., Slack, OpsGenie) and the schedule for drift detection jobs.

from scouter.alert import SpcAlertConfig, OpsGenieDispatchConfig, SpcAlertRule
from scouter.types import CommonCrons
SpcAlertConfig(
rule=SpcAlertRule(rule="16 32 4 8 2 4 1 1"),
dispatch_config=OpsGenieDispatchConfig(team='the-ds-team'),
schedule=CommonCrons.EveryDay,
features_to_monitor=['feature_1', 'feature_2', ...],
)
ParameterTypeDescriptionExample
dispatch_config`SlackDispatchConfigOpsGenieDispatchConfigNone`
schedule`strCommonCronsNone`
features_to_monitorlist[str]List of features to monitor. Defaults to empty list, which means all featuresconfig.features_to_monitor → ['feature_1, feature_2, ...']
ruleSpcAlertRuleDefines the conditions for triggering alerts based on patterns observed in the control chart. Defaults to “8 16 4 8 2 4 1 1”, where each digit specifies a threshold for detecting instability within each control zone (Zone 1 to Zone 4). Can be customized for more or less sensitivity.config.rule → *Instance of SpcAlertRule*
PropertyTypeDescriptionExample
dispatch_typestrString representation of what type of dispatch are you using to send alerts.config.dispatch_type"Slack"
dispatch_Config`SlackDispatchConfigOpsGenieDispatchConfigNone`
schedulestrThe schedule that is used to determine when your drift detecion job should run.config.schedule"0 0 0 * * SUN"
features_to_monitorlist[str]List of features to monitor.config.features_to_monitor → ['feature_1, feature_2, ...']
ruleSpcAlertRuleDefines the conditions for triggering alerts based on patterns observed in the control chart. Defaults to “8 16 4 8 2 4 1 1”, where each digit specifies a threshold for detecting instability within each control zone (Zone 1 to Zone 4). Can be customized for more or less sensitivity.config.rule → *Instance of SpcAlertRule*

The SpcAlertRule class is used to define the conditions for triggering alerts based on patterns observed in the control chart. The rule is represented as a string of digits, where each digit specifies a threshold for detecting instability within each control zone (Zone 1 to Zone 4). The default rule is “8 16 4 8 2 4 1 1”, which can be customized for more or less sensitivity.

rom scouter.alert import SpcAlertRule, AlertZone
SpcAlertRule(
rule="8 16 4 8 2 4 1 1",
zones_to_monitor=[AlertZone.Zone1, AlertZone.Zone2, AlertZone.Zone3, AlertZone.Zone4]
)
ParameterTypeDescriptionExample
rulestrRule to use for alerting. Eight digit integer string. Defaults to ‘8 16 4 8 2 4 1 1alert_rule.rule -> "8 16 4 8 2 4 1 1"
zones_to_monitorlist[AlertZone]List of zones to monitor. Defaults to all zones.alert_rule.zones → [AlertZone.Zone1, AlertZone.Zone2]
PropertyTypeDescriptionExample
rulestrRule to use for alerting. Eight digit integer string. Defaults to ‘8 16 4 8 2 4 1 1alert_rule.rule -> "8 16 4 8 2 4 1 1"
zones_to_monitorlist[AlertZone]List of zones to monitor. Defaults to all zones.alert_rule.zones → [AlertZone.Zone1, AlertZone.Zone2]