scikit 学习错误 - 100. * self.contamination) TypeError: unsupported operand type(s) for *: 'float'和'type'

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

我试图为一个csv文件建立一个隔离森林,我从不同的大小值中预测 "页面"。页数 "值目前是 "低 "和 "高",我已经将它们编码为0和1,这样我就可以检测异常。然而,我一直得到错误' 文件 "LibraryFrameworksPython.frameworkVersions3.8libpython3.8site-packagessklearnensemble_iforest.py",第312行,在fit 100. * self.contamination)TypeError: unsupported operand type(s) for *: 'float'和'type''

我把代码附在下面,非常感谢您的帮助!

label_encoder = LabelEncoder()
integer_encoded=label_encoder.fit_transform(values)
print(integer_encoded)
print(len(integer_encoded))
df['pages']= integer_encoded
X = df.iloc[:, 0:101].values
y = df['pages']
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 = 50, max_samples = 'auto', contamination = float)
model.fit(df[['pages']])
scikit-learn isolation
1个回答
1
投票

所以SciKit是开源的,你可以在这里看到你需要的文件。https:/github.comscikit-learnscikit-learnblob8feb04524caf78c6a84b56fc59917a0eadcb69c2sklearnensemble_iforest.py。

_iforest.py

问题行是2020年6月11日最新的283行。

然后你可以看看上面的 init 该文件的,并看到 contamination 是构造函数中的一个参数。 如果你不传递它,它就会使用 auto 默认值为 0.5

你需要确保你通过一个浮子作为 contamination 值时,初始化森林

EDIT: 请注意,你不需要为 contamination 因为它有那个默认值

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