我正在尝试训练SVM进行异常检测。为此,我仅使用sourceip和协议创建了train_data和test_data。但是,当我尝试使用绘图功能时,它会给我以下错误...
> plot(svmfit,testdat)
Error in Summary.factor(c(7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, :
min not meaningful for factors
我怎样才能摆脱这个错误..?
以下是外部文件中的命令行
train_data=read.csv("packetcapture_training.csv")
#read only source ip and protocol
xtrain=train_data[4:23,c(3,5)]
ytrain=c(rep(-1,10),rep(1,10))
dat=data.frame(x=xtrain,y=as.factor(ytrain))
library("e1071")
svmfit=svm(y~.,data=dat,kernel="radial",cost=10,scale=FALSE)
summary(svmfit)
test_data=read.csv("packetcapture_testing.csv")
#read only source ip and protocol
xtest=test_data[371:390,c(3,5)]
ytest=c(rep(1,10),rep(-1,10))
testdat=data.frame(x=xtest,y=as.factor(ytest))
plot(svmfit,testdat)
> dat
x.Source x.Protocol y
1 fe80::a00:27ff:feee:7ec6 ICMPv6 -1
2 fe80::a00:27ff:feee:7ec6 ICMPv6 -1
3 fe80::a00:27ff:feee:7ec6 ICMPv6 -1
4 172.16.11.1 TCP -1
5 192.168.2.101 TCP -1
6 172.16.11.1 TCP -1
7 172.16.11.1 TCP -1
8 172.16.11.1 TCP -1
9 192.168.2.101 TCP -1
10 192.168.2.101 TCP -1
11 172.16.11.1 TCP 1
12 172.16.11.1 TCP 1
13 172.16.11.1 TCP 1
14 192.168.2.101 TCP 1
15 172.16.11.1 TCP 1
16 192.168.2.101 TCP 1
17 172.16.11.1 TCP 1
18 172.16.11.1 TCP 1
19 192.168.2.101 SSHv2 1
20 172.16.11.1 TCP 1
> dput(head(dat,4))
structure(list(x.Source = structure(c(6L, 6L, 6L, 1L), .Label = c("172.16.11.1",
"192.168.2.100", "192.168.2.101", "CadmusCo_8b:7b:80", "CadmusCo_ee:7e:c6",
"fe80::a00:27ff:feee:7ec6"), class = "factor"), x.Protocol = structure(c(5L,
5L, 5L, 7L), .Label = c("ARP", "DNS", "HTTP", "ICMP", "ICMPv6",
"SSHv2", "TCP", "UDP"), class = "factor"), y = structure(c(1L,
1L, 1L, 1L), .Label = c("-1", "1"), class = "factor")), .Names = c("x.Source",
"x.Protocol", "y"), row.names = c(NA, 4L), class = "data.frame")
> testdat
x.Source x.Protocol y
371 172.16.11.1 TCP 1
372 172.16.11.1 TCP 1
373 172.16.11.1 TCP 1
374 172.16.11.1 TCP 1
375 172.16.11.1 TCP 1
376 172.16.11.1 TCP 1
377 172.16.11.1 TCP 1
378 172.16.11.1 TCP 1
379 172.16.11.1 TCP 1
380 172.16.11.1 TCP 1
381 172.16.11.1 TCP -1
382 172.16.11.1 TCP -1
383 172.16.11.1 TCP -1
384 172.16.11.1 TCP -1
385 172.16.11.1 TCP -1
386 172.16.11.1 TCP -1
387 172.16.11.1 TCP -1
388 172.16.11.1 TCP -1
389 192.168.2.101 SSHv2 -1
390 192.168.2.101 ICMPv6 -1
> dput(head(testdat,4))
structure(list(x.Source = structure(c(1L, 1L, 1L, 1L), .Label = c("172.16.11.1",
"192.168.2.100", "192.168.2.101", "CadmusCo_8b:7b:80", "CadmusCo_ee:7e:c6",
"fe80::a00:27ff:feee:7ec6"), class = "factor"), x.Protocol = structure(c(7L,
7L, 7L, 7L), .Label = c("ARP", "DNS", "HTTP", "ICMP", "ICMPv6",
"SSHv2", "TCP", "UDP"), class = "factor"), y = structure(c(2L,
2L, 2L, 2L), .Label = c("-1", "1"), class = "factor")), .Names = c("x.Source",
"x.Protocol", "y"), row.names = 371:374, class = "data.frame")
答案 0 :(得分:-2)
plot.svm
中的library("e1071")
函数显然只是想绘制连续预测变量。由于您的模型使用两个分类预测变量,因此您会收到该错误。你知道你期待什么样的可视化吗?
在帮助页面的示例中,显示
data(cats, package = "MASS")
m <- svm(Sex~., data = cats)
plot(m, cats)
并且它可以在一个范围内展开点,并且切割可以在有意义的断点处发生。对于分类预测因子,它们不是有序的,因此没有明确的方法以类似的方式绘制它们。