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

invalid 'ncol' value (< 0) in R

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

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) 

看看你的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