python - 应用聚类算法后尝试使用标签编码器进行逆变换时出现值错误
问题描述
我在哪里使用标签编码器来标记分类列。但是,在将其转换回来时,我遇到了价值错误
我使用了 sklearn 的标签编码器
代码:
from sklearn.preprocessing import LabelEncoder
enc = LabelEncoder()
label_encoder = enc.fit(Final.iloc[:,3])
print ("Categorical classes:", label_encoder.classes_)
integer_classes = label_encoder.transform(label_encoder.classes_)
print ("Integer classes:", integer_classes)
t = label_encoder.transform(Final.iloc[:,3])
Final.iloc[:, 3] = t
data = Final.iloc[:,3:11]
from sklearn.ensemble import IsolationForest
import numpy as np
clf=IsolationForest(n_estimators=100, max_samples='auto', contamination=float(.03))
clf.fit(data)
pred = clf.predict(data)
Final['anomaly']=pred
outliers=Final.loc[Final['anomaly']==-1]
outlier_index=list(outliers.index)
print(Final['anomaly'].value_counts())
t = label_encoder.inverse_transform(Final.iloc[:,3])
Final.iloc[:,3] = t
错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
解决方案
推荐阅读
- java - 如何在 Eclipse 中将 Spring Boot 应用程序转换为 Dynamic Web 项目?
- python - 如何改进我的代码,使其不显示超时错误
- python - Pandas 将 CSV 中的空单元格识别为 EMPTY SPACE 而不是 nan
- python - 使用 ctypes 传递可变数量的自定义类型参数
- python - 使用未观察到的组件模型模拟时间序列
- angular - Angular:如何使用 agggrid 和 HttpClient delete 从我的 json 服务器中删除用户?
- google-maps-api-3 - 在谷歌地图 v3 Javascript 中重置标记图标
- javascript - PEGjs 可以将语句的“结束”字符作为输入吗?
- python - 使用 Python/Pandas 获取 Excel 列中的最大值并显示行名
- cuda - 等效于 CUDA 中的屏障(CLK_GLOBAL_MEM_FENCE)