是不良來源,還是壞目的地?
在上一個單元,你把「目的地」電腦當成分析的主體。不過,資安分析師剛告訴你,實際上是遭到感染的機器在產生惡意流量,因此它們會出現在 flows 資料集的「來源」欄位,而不是目的地。
flows 資料已經預先載入,還有上一個單元的感染 ID 清單 bad、以及特徵萃取器 featurizer()。你也可以使用 numpy(縮寫為 np)、AdaBoostClassifier(),以及 cross_val_score()。
本練習屬於課程
在 Python 設計機器學習工作流程
練習說明
- 建立一個資料框,讓每一列都是
source_computer的特徵向量。請在flows資料集中依來源電腦 ID 分組,並對每個分組套用特徵萃取器。 - 對該迭代器呼叫
list(),將其轉為資料框。 - 依你拿到的不良清單,檢查每個
source_computerID 是否在其中,據以建立標籤。 - 使用
cross_val_score()評估一個AdaBoostClassifier()。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Group by source computer, and apply the feature extractor
out = flows.____('source_computer').____(featurize)
# Convert the iterator to a dataframe by calling list on it
X = pd.DataFrame(____, index=____)
# Check which sources in X.index are bad to create labels
y = [x in bads for x in ____]
# Report the average accuracy of Adaboost over 3-fold CV
print(np.mean(____(____, X, y)))