scikit 学习错误 - 100。* 自我污染) 类型错误: 不支持的操作数类型 *: 'float' 和 'type'



我正在尝试为我根据各种大小值预测"页面"的 csv 文件构建隔离林。"pages"值目前为"低"和"高",我已将它们编码为 0 和 1,以便我可以检测异常。但是,我不断收到错误" File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sklearn/ensemble/_iforest.py",第 312 行,适合 100. * 自我污染( 类型错误:* 不支持的操作数类型:"浮点型"和"类型">

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

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是开源的,你可以在这里看到你需要的文件: https://github.com/scikit-learn/scikit-learn/blob/8feb04524caf78c6a84b56fc59917a0eadcb69c2/sklearn/ensemble/_iforest.py

_iforest.py

有问题的线路是截至2020年6月11日的最新283行

然后,您可以在上面查看此文件的init,并看到contamination是构造函数中的参数。 如果不传递它,它将使用auto将值默认为0.5

您需要确保在初始化林时传递浮点数作为contamination

编辑:请注意,您不需要将任何内容传递到contamination的构造函数/初始化中,因为它具有该默认值

相关内容

最新更新