python - pycaret 和 H2O 之间异常检测的不同结果

标签 python h2o anomaly-detection pycaret

我正在从以下数据中检测异常:
enter image description here
它来自液压系统的处理信号,从那里我知道红框中的点是系统故障时发生的异常。
我正在使用前 3k 条记录来训练模型,包括 pycaret 和 H20。这 3k 条记录涵盖了 5 个数据周期,如下图所示:
要在 pycaret 中训练模型,我使用以下代码:
enter image description here

from pycaret.anomaly import *
from pycaret.datasets import get_data
import pandas as pd
exp_ano101 = setup(df[["Pressure_median_mw_2500_ac"]][0:3000], normalize = True, 
                   session_id = 123)

iforest = create_model('iforest')
unseen_predictions = predict_model(iforest, data=df[["Pressure_median_mw_2500_ac"]])
unseen_predictions = unseen_predictions.reset_index()
我从 pycaret 得到的结果非常好:
enter image description here
通过一些后期处理,我可以获得以下效果,这非常接近理想状态:
enter image description here
另一方面,使用 H20,代码如下:
import pandas as pd
from h2o.estimators import H2OIsolationForestEstimator, H2OGenericEstimator
import tempfile
ifr = H2OIsolationForestEstimator()
ifr.train(x="Pressure_median_mw_2500_ac",training_frame=hf)
th = df["mean_length"][0:3000].quantile(0.05)
df["anomaly"] = df["mean_length"].apply(lambda x: "1" if x> th  else "0")
我明白了:
enter image description here
这是一个巨大的差异,因为它没有将此块检测为异常:
enter image description here
我的疑问是,鉴于我使用的是相同的算法,即隔离森林,我怎样才能获得与从 pycaret 获得的结果相似的结果。甚至在 Pycaret 中使用 SVM 也比在 H2O 中使用隔离森林得到更接近的结果
enter image description here

最佳答案

Pycaret 使用库 PyOD 进行异常检测。然后是 PyOD 与 H2O。也许有不同的默认参数。在 Pycaret (PyOD) 中可以修改参数分数 - 默认值 = 0.05,数据集中异常值的百分比/比例。
您应该尝试使用此参数,也许您会从两个库中获得相同的结果。

关于python - pycaret 和 H2O 之间异常检测的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68461155/

相关文章:

python - 如何用 True、False 和颜色编码 Python 绘图来标记 Y 轴?

python - 将列表绑定(bind)到 Pandas read_sql_query 中的参数和其他参数

java - 在 R 中使用 h2o.init() 时出错 - Java 相关

python - 完成 h2o 操作后删除进度条

r - 如何在 R 中的两个 H2OFrame 之间进行交叉连接?

machine-learning - 在异常检测中查找原因根源

python - 基于其他列在 DataFrame 中创建新列

python - 如何使用python3修复日期格式

python - 修改 pandas 数据框的列标题

algorithm - 检测转换数据持续下降模式的最佳算法