R中无效的'ncol'值(< 0)

时间:2017-04-18 06:49:49

标签: r fuzzy

我正在尝试 frbcs.w 功能,并使用虹膜数据的示例代码来训练和测试数据。我的数据是370条评论的10个特征得分。所以它是一个10 X 370的矩阵。我第一次使用R,即使只获取了与虹膜数据集相似的部分数据,它也显示出错误,如下所示:< / p>

Error in matrix(nrow = nrow(rule.data.num), ncol = 2 * ncol(rule.data.num) - :  invalid 'ncol' value (< 0)

我的数据集采用csv格式:dataset 我还从我的370条评论数据集中添加了20条评论的样本:

F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,OUTPUT
0,0,0,0,0,0,0,0,0,0,high
0,0.541667,0,0,0,0.455729,0,0,0,0,high
0,0,0,0,0,0.375,0,0,0,0,high
0.333333,0,0,0,0,0.575,0,0,0,0,medium
0.5,0.5,0,0,0,0.333333,0,0,1,0.625,high
0,0,0,0,0,0.6875,0,0,0,0.875,high
0,0.125,0,0,0,0.234375,0,0,0,0,medium
0.375,0,0,0,0,0.5,0,0,0,0,low
0,0,0,0,0,0,0,0,0,0,low
0,0,0,0,0,0.244792,0,0,0,0,low
0.234375,0.875,0,0.234375,0,0.5,0,0,0,0.5,low
0,0,0,0,0,0.643229,0,0,0,0.25,high
0,0.40625,1,0,0,0.421875,0,0,0,0,low
0.875,0.375,1,0,0,0.810547,0,0,0,0.375,high
0,0,0,0,0,0,0,0,0,0,high
0,0,0,0,0,0.187798,0,0,0,0.875,low
1,0,0,0,0,0,0,0,0,0.125,high
0.0625,0,0.5,0.5,0,0.5,0,0,0.9375,0.833333,medium
0,0,0,0,0,0.875,0,0,0,0,low
0,0,0,0.25,0,0,0,0,0,0,high

我正在尝试的代码是:

library(frbs)

ir <- read.csv("Output3.csv")
set.seed(2)
irShuffled <- ir[sample(nrow(ir)),]
irShuffled[,11] <- unclass(irShuffled[,11])
tra.ir <- irShuffled[1:300,]
tst.ir <- irShuffled[301:nrow(irShuffled),1:10]
real.ir <- matrix(irShuffled[301:nrow(irShuffled),11], ncol = 1)
range.data.input <- matrix(c(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), nrow=2)

method.type <- "FRBCS.W"
control <- list(num.labels = 7, type.mf = "GAUSSIAN", type.tnorm = "MIN", 
            type.snorm = "MAX", type.implication.func = "ZADEH")  

## Generate fuzzy model
object <- frbs.learn(tra.ir, range.data.input, method.type, control)

## Predicting step
res.test <- predict(object, tst.ir)

## error calculation
err = 100*sum(real.ir!=res.test)/nrow(real.ir)

print("The result: ")
print(res.test)
print("FRBCS.W: percentage Error on Ir-")
print(err) 

1 个答案:

答案 0 :(得分:0)

查看您的range.data.input向量。

> range.data.input
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    1    1    1    0    0    0    0     0
[2,]    1    1    1    1    1    0    0    0    0     0

替换你的程序
range.data.input <- matrix(rep(c(0.0, 1.0), 10), nrow=2)

> range.data.input
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    0    0    0    0    0    0    0    0    0     0
[2,]    1    1    1    1    1    1    1    1    1     1