在 Python 設計機器學習工作流程
Dr. Chris Anagnostopoulos
Honorary Associate Professor
真實程度:
無雜訊或「強」標籤:
有雜訊或「弱」標籤:
特徵工程:
每個受感染主機造訪的唯一連接埠平均數:
np.mean(X[y]['unique_ports'])
15.11
忽略標籤時,每台主機造訪的唯一連接埠平均數:
np.mean(X['unique_ports'])
11.23
將特徵轉為標註啟發式:
X_train, X_test, y_train, y_test = train_test_split(X, y)
y_weak_train = X_train['unique_ports'] > 15


X_train_aug = pd.concat([X_train, X_train])
y_train_aug = pd.concat([pd.Series(y_train), pd.Series(y_weak_train)])

weights = [1.0]*len(y_train) + [0.1]*len(y_weak_train)
只用 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 設計機器學習工作流程