我已经使用 NSL-KDD 数据集训练了一个 SVM,但是当我尝试对其进行预测时,它出现了错误“不允许使用负维度”。
下面是我的代码:
#Indexing of features and labels
features = dataset[:,:-2]
labels = dataset[:,-2]
#encode
encode = LabelEncoder()
enclabels = encode.fit_transform(labels)
#split data
train_features, test_features, train_labels, test_labels = train_test_split(features, labels, test_size=0.2)
#train model
model = SVC(C=1.0, kernel='rbf')
# create classifier
classifier = SklearnClassifier(model=model)
#Train classifier
model.fit(train_features, train_labels)
predictions = classifier.predict(test_features)
我以为可能会有数据不匹配但是当我运行以下代码时,我得到了这个:
`print(np.shape(test_features))
(5039, 38)
print(np.shape(test_labels))
(5039,) `
谁能帮我解决这个错误?将不胜感激。
编辑-带有回溯的完整错误:
File ~\OneDrive\Documents\ids\fgsm.py:50 in <module>
predictions = classifier.predict(test_features)
File ~\AppData\Roaming\Python\Python39\site-packages\art\estimators\classification\classifier.py:73 in replacement_function
return fdict[func_name](self, *args, **kwargs)
File ~\AppData\Roaming\Python\Python39\site-packages\art\estimators\classification\scikitlearn.py:1418 in predict
one_hot_targets = np.eye(self.nb_classes)[targets]
File C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\twodim_base.py:214 in eye
m = zeros((N, M), dtype=dtype, order=order)
ValueError: negative dimensions are not allowed