隔离林键错误:"None of [Index([], dtype='object')] are in the [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='object'(

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:";[索引(['frame.len'],dtype='object'(]都不在[列]中;

我的错误在哪里?

提前感谢

数据帧有许多数据点,但只有一列。

print(quelle.shape)
(1658, 1)

当您将文件加载到数据帧中时,它无法自动检测文件的正确分隔符,它没有读取每一列,而是将所有列打包到一列中。

若要解决此问题,应在读取文件时指定分隔符。

pd.read_csv('./x.csv', sep=';')

最新更新