开始使用免费开始使用

是源头坏,还是目标坏?

在上一课中,您把"目标"计算机作为关注的实体。不过,网络安全分析师刚刚告诉您,产生恶意流量的是被感染的机器,因此它们会在 flows 数据集中作为"源头"出现,而不是目标。

数据 flows 已预加载,同时还有上一课中的被感染 ID 列表 bad 和特征提取器 featurizer()。您还可以使用以 np 导入的 numpyAdaBoostClassifier(),以及 cross_val_score()

本练习是课程的一部分

用 Python 设计机器学习工作流

查看课程

练习说明

  • 创建一个数据框,其中每一行都是一个 source_computer 的特征向量。在 flows 数据集中按源计算机 ID 分组,并对每个分组应用特征提取器。
  • 通过对该迭代器调用 list(),将其转换为数据框。
  • 通过检查每个 source_computer 的 ID 是否属于给定的坏样本列表,来创建标签。
  • 使用 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)))
编辑并运行代码