一个简单的新奇点检测
您认为新奇点检测比离群点检测更有用,但想先确认它能在之前的简单示例上正常工作。这一次,您将使用由 30 个取值均为 1.0 的样本组成的序列作为训练集,并检查样本 10.0 是否会被标记为新奇点。您可以使用 pandas(简称 pd)和 LocalOutlierFactor 模块(简称 lof)。
本练习是课程的一部分
用 Python 设计机器学习工作流
练习说明
- 创建一个 pandas DataFrame,包含 30 个取值都为
1.0的样本。 - 初始化一个基于局部离群因子的的新奇点检测器。
- 将检测器拟合到训练数据上。
- 输出数据点
10.0的新奇点标签,并将其转换为 DataFrame 后再预测。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a list of thirty 1s and cast to a dataframe
X = ____([1.0]*30)
# Create an instance of a lof novelty detector
detector = lof(____)
# Fit the detector to the data
detector.____(____)
# Use it to predict the label of an example with value 10.0
print(detector.____(____(____)))