python - IsolationForest KeyError:“[Index([''], dtype='object')] 均不在 [columns] 中”
问题描述
我正在尝试使用 IsolationForest 实现我的第一个异常检测,但不幸的是它没有成功。
我有一个.csv
具有不同网络参数的文件,例如 ip.ttl、frame.len 等。
#Einlesen
quelle = pd.read_csv('./x.csv')
pdf=quelle.to_numpy()
print(quelle.columns)
索引([';ip.proto;ttl;frame.len;ip.src;ip.dst;ip.len;ip.flags;eth.src;eth.dst;eth.type;vlan.id;udp.port '], dtype='对象')
print(quelle.shape)
(1658, 1)
但是,当我尝试使用 ip.ttl 或 frame.len(其中一列)之类的列创建 IsolationForest 模型时,出现错误
model=IsolationForest(n_estimators=50, max_samples='auto',contamination=float(0.1),max_features=1.0)
model.fit(quelle[['frame.len']])
KeyError:“[Index(['frame.len'], dtype='object')] 均不在 [columns] 中”
我的错误在哪里?
提前致谢
解决方案
数据框有许多数据点,但只有一列。
print(quelle.shape)
(1658, 1)
当您将文件加载到数据框中时,它无法自动检测文件的正确分隔符是什么,而不是读取每一列,而是将所有列打包到一个列中。
要解决此问题,您应该在读取文件时指定分隔符。
pd.read_csv('./x.csv', sep=';')
推荐阅读
- python - 根据百分比变化值绘制多条线图
- python - 带有 sum() 和 apply() 的 Python 数据框轴的工作方式不同
- asp.net-core - 使用两个项目的电子邮件确认身份(一个用于发送令牌,一个用于确认)
- java - 列表
to json 给出不完整的 json 列表 - php - gmail 用户不会收到 Laravel 邮件
- mysql - 如何在sql中选择比他们各自部门的领导赚更多钱的工人?
- python - sort_value pandas 函数的问题,要求“by”,但给出时,会说意外的参数
- javascript - ReactJS 中 Safari 的 JQuery UI Datepicker 回退
- python - Python Pulp - 没有重复的名称
- node.js - 在 POST 请求上反应 Axios ECONNRESET