【发布时间】:2020-10-01 14:06:48
【问题描述】:
我正在尝试使用 scikit learn 和 python 构建一个隔离林来检测异常。我附上了一张数据可能是什么样子的图像,我试图根据几个“大小”特征来预测“页面”。 当我打印(异常)时,每一行都被检测为-1,一个异常。这是因为我只使用“size2”对它们进行分类吗?有没有办法使用多列来帮助检测异常?我应该使 n_features 等于我正在使用的列数吗?非常感谢你的帮助。
model = IsolationForest(n_estimators = 100, max_samples = 'auto', contamination = 'auto')
model.fit(df[['pages']])
df['size2'] = model.decision_function(df[['pages']])
df['anomaly']= model.predict(df[['pages']])
print(df.head(50))
anomaly = df.loc[df['anomaly']==-1]
anomaly_index = list(anomaly.index)
print(anomaly)
【问题讨论】: