單變量漂移偵測

在 Python 中監控 Machine Learning

Hakim Elakhrass

CEO and co-founder

什麼是單變量漂移偵測?

此圖顯示監控工作流程,以及單變量方法在其中的位置。

在 Python 中監控 Machine Learning

單變量方法

  • Jensen-Shannen 距離-類別與連續皆適用
  • Hellinger-類別與連續皆適用
  • Wasserstein-僅限連續
  • Kolgomorov-Smirnov-僅限連續

  • L-infinity-僅限類別

  • Chi2-僅限類別

1 https://nannyml.readthedocs.io/en/stable/how_it_works/univariate_drift_comparison.html
在 Python 中監控 Machine Learning

程式碼實作

# 初始化單變量漂移計算器
uv_calc = nannyml.UnivariateDriftCalculator(
    continuous_methods=['wasserstein', 'hellinger'],
    categorical_methods=['jensen_shannon', 'l_infinity', 'chi2'],
    column_names=feature_column_names,
    timestamp_column_name='timestamp',
    chunk_period='d'
    )
# 擬合、計算並繪圖
uv_calc.fit(reference)
uv_results = uv_calc.calculate(analysis)
uv_results.plot().show()
在 Python 中監控 Machine Learning

結果篩選

  • 依欄位名稱過濾
  • 依單變量方法過濾
# 篩選單變量結果
filtered_figure = uv_results.filter(column_names=['trip_distance', 'fare_amount'], 
            methods=['jensen_shannon'])

# 繪製篩選後結果
filtered_figure.show().plot()
在 Python 中監控 Machine Learning

警示計數排序器

  • 依警示次數對特徵排序
# 初始化警示計數排序器
alert_count_ranker = nannyml.AlertCountRanker()
alert_count_ranked_results = alert_count_ranker.rank(
    uv_results,
    only_drifting=False)
# 顯示結果
display(alert_count_ranked_results)

此圖顯示某些特徵的警示次數資料框。

在 Python 中監控 Machine Learning

相關性排序器

  • 依與效能絕對變化的相關程度對特徵排序
# 初始化相關性排序器
correlation_ranker = nannyml.CorrelationRanker()
correlation_ranker.fit(perf_results.filter(period='reference'))
correlation_ranked_results = correlation_ranker.rank(uv_results, perf_results)

# 顯示結果
display(correlation_ranked_results)

此圖顯示每個特徵的 Pearson 相關與 p 值資料框。

在 Python 中監控 Machine Learning

監控特徵分布

  • 提供更深入洞見並提升可解釋性
# 建立分布圖
distribution_results = uv_results.plot(kind='distribution')

# 顯示圖表
distribution_results.show()
在 Python 中監控 Machine Learning

特徵分布圖

 

此圖顯示連續與類別特徵的分布圖。

在 Python 中監控 Machine Learning

一起來練習吧!

在 Python 中監控 Machine Learning

Preparing Video For Download...