孤立森林在预测一个点而不是全部时给出不同的结果

问题描述 投票:0回答:1

我正在尝试检测某些数据中的异常。我有正常数据和被认为是异常的数据。

我使用python的scikit-learn库中的Isolation Forest。我已经从像这样的普通数据创建了一个模型:

model = IsolationForest(n_estimators=100, contamination=0.002)
model.fit(new_features)

[当我尝试进行预测时:

predicted = model.predict(transformed_anomaly)

它正常工作。在36个异常中,有35个被检测为异常。

如果我这样做:

for anomaly in transformed_anomaly:
   predicted = model.predict(anomaly.reshape(1,-1))

突然所有点都归为内点。

我检查了'anomaly.reshape(1,-1)'的形状,它是(1、2)。'transformed_anomaly'的形状为(36,2)

有人可以指出问题所在吗?

python scikit-learn outliers isolation anomaly-detection
1个回答
0
投票

在隔离林中传递random_state = 0可以在每次运行中获得相同的结果。模型= IsolationForest(n_estimators = 100,污染= 0.002,,random_state = 0)

© www.soinside.com 2019 - 2024. All rights reserved.