首页 > 解决方案 > 每次运行都发现不同的异常 - 隔离森林

问题描述

我使用 sklearn 和 Python 构建了一个隔离森林,每次运行模型来查找异常时,我得到的结果都略有不同。

我的数据有 100 行,每次我在第 90-100 行中得到 4-8 个异常的不同组合,有谁知道为什么会这样?

谢谢您的帮助。我附上了一些我用过的代码。

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
model = IsolationForest(n_estimators = 100, max_samples = 'auto', 
contamination = 'auto')
model.fit(df[['label']])
anomaly = df.loc[df['anomaly']==-1]

标签: pythonanomaly-detection

解决方案


推荐阅读