【发布时间】:2014-07-06 03:52:52
【问题描述】:
我正在尝试训练 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")
【问题讨论】:
-
因为您没有包含任何数据,所以此错误无法重现。如果您想让人们更容易地帮助您,请参阅How to make a great R reproducible example?上的指南
-
抱歉信息较少。我不确定这是否足够...我想,我在列格式方面犯了一个错误...我应该如何格式化 IP 地址以进行 SVM 学习。 ..