標籤、弱標籤與真相

在 Python 設計機器學習工作流程

Dr. Chris Anagnostopoulos

Honorary Associate Professor

標籤不一定完美

真實程度:

  • Ground truth
    • 電腦當機並顯示勒索訊息
  • 專家人工標註
    • 分析師檢視電腦日誌,找出未授權行為
  • 啟發式標註
    • 在極短時間內太多連接埠收到流量
在 Python 設計機器學習工作流程

標籤不一定完美

無雜訊或「強」標籤:

  • Ground truth
  • 專家人工標註

有雜訊或「弱」標籤:

  • 啟發式標註

特徵工程:

  • 用於啟發式的特徵
在 Python 設計機器學習工作流程

特徵與啟發式

每個受感染主機造訪的唯一連接埠平均數:

np.mean(X[y]['unique_ports'])
15.11

忽略標籤時,每台主機造訪的唯一連接埠平均數:

np.mean(X['unique_ports'])
11.23
在 Python 設計機器學習工作流程

從特徵到標籤

將特徵轉為標註啟發式:

X_train, X_test, y_train, y_test = train_test_split(X, y)
y_weak_train = X_train['unique_ports'] > 15

裁切後的直方圖

在 Python 設計機器學習工作流程

從特徵到標籤

將特徵矩陣疊成兩份:一份有領域專家產生的標籤,另一份用啟發式產生標籤。

X_train_aug = pd.concat([X_train, X_train])
y_train_aug = pd.concat([pd.Series(y_train), pd.Series(y_weak_train)])
在 Python 設計機器學習工作流程

與前一張投影片相同的堆疊資料,但給原始標籤權重 1.0,啟發式標籤權重 0.5。

weights = [1.0]*len(y_train) + [0.1]*len(y_weak_train)
在 Python 設計機器學習工作流程

只用 ground truth 的準確率:

0.91

ground truth 加弱標籤(無權重):

accuracy_score(y_test, clf.fit(X_train_aug, y_train_aug).predict(X_test))
0.93

加入權重:

accuracy_score(y_test, clf.fit(X_train_aug, y_train_aug, sample_weight=weights).predict(X_test))
0.95
在 Python 設計機器學習工作流程

標籤不必完美!

在 Python 設計機器學習工作流程

Preparing Video For Download...