Designing Machine Learning Workflows in Python
Dr. Chris Anagnostopoulos
Honorary Associate Professor
Degrees of truth:
Noiseless or strong labels:
Noisy or weak labels:
Feature engineering:
Average of unique ports visited by each infected host:
np.mean(X[y]['unique_ports'])
15.11
Average of unique ports visited per host disregarding labels:
np.mean(X['unique_ports'])
11.23
Convert a feature into a labeling heuristic:
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)
Accuracy using ground truth only:
0.91
Ground truth and weak labels without weights:
accuracy_score(y_test, clf.fit(X_train_aug, y_train_aug).predict(X_test))
0.93
Add weights:
accuracy_score(y_test, clf.fit(X_train_aug, y_train_aug, sample_weight=weights).predict(X_test))
0.95
Designing Machine Learning Workflows in Python