t中的错误(as(from,“;ngCMatrix)):计算参数时的错误‘;x’;在选择函数的方法时‘;t’;:asM中的错误

t中的错误(as(from,“;ngCMatrix)):计算参数时的错误‘;x’;在选择函数的方法时‘;t’;:asM中的错误,r,matrix,sparse-matrix,knime,R,Matrix,Sparse Matrix,Knime,我在数据分析平台Knime中使用R代码。我从一个从xls文件中读取表格的块中获取一个矩阵。该矩阵称为“我的矩阵”。然后我想将apriori算法应用于这个矩阵的三列,但是我得到了上面的错误。有什么想法吗? 请注意,“sum(is.na(my_矩阵))”的输出为[1]0 require(arules) #require(arulesViz) #some code to retreive the my_matrix #my_matrix my_rows= nrow(my_matrix); my_c

我在数据分析平台Knime中使用R代码。我从一个从xls文件中读取表格的块中获取一个矩阵。该矩阵称为“我的矩阵”。然后我想将apriori算法应用于这个矩阵的三列,但是我得到了上面的错误。有什么想法吗? 请注意,“sum(is.na(my_矩阵))”的输出为[1]0

require(arules)
#require(arulesViz)

#some code to retreive the my_matrix

#my_matrix
my_rows= nrow(my_matrix);
my_cols= ncol(my_matrix);
matrix_temp = my_matrix[,4:5];
matrix_temp = array(c(matrix_temp, my_matrix[,20]), dim=c(my_rows,3))
#matrix_temp
my_matrix = matrix_temp

sum(is.na(my_matrix)) #output: [1] 0

my_transactions = as(my_matrix, "transactions");
summary(my_transactions)
my_matrix是一个表,其中的列为以下类型:(String、Integer、Integer、String、String、Integer、Double、Integer、Double、Integer、Double、Integer、Double、Integer、Double、Integer、String)。表中有3300行

> my_matrix = as(knime.in, "matrix")
> dput(head(my_matrix, 5))
structure(c("KS", "OH", "NJ", "OH", "OK", "128", "107", "137", 
" 84", " 75", "415", "415", "415", "408", "415", "noIP", "noIP", 
"noIP", "IP", "IP", "Vmail", "Vmail", "noVmail", "noVmail", "noVmail", 
"25", "26", " 0", " 0", " 0", "265.1", "161.6", "243.4", "299.4", 
"166.7", "110", "123", "114", " 71", "113", "45.07", "27.47", 
"41.38", "50.90", "28.34", "197.4", "195.5", "121.2", " 61.9", 
"148.3", " 99", "103", "110", " 88", "122", "16.78", "16.62", 
"10.30", " 5.26", "12.61", "244.7", "254.4", "162.6", "196.9", 
"186.9", " 91", "103", "104", " 89", "121", "11.01", "11.45", 
" 7.32", " 8.86", " 8.41", "10.0", "13.7", "12.2", " 6.6", "10.1", 
" 3", " 3", " 5", " 7", " 3", "2.70", "3.70", "3.29", "1.78", 
"2.73", "1", "1", "0", "2", "3", "notChurning", "notChurning", 
"notChurning", "notChurning", "notChurning"), .Dim = c(5L, 20L
), .Dimnames = list(c("Row0", "Row1", "Row2", "Row3", "Row4"), 
    c("State", "Account length", "Area code", "International plan", 
    "Voice mail plan", "Number vmail messages", "Total day minutes", 
    "Total day calls", "Total day charge", "Total eve minutes", 
    "Total eve calls", "Total eve charge", "Total night minutes", 
    "Total night calls", "Total night charge", "Total intl minutes", 
    "Total intl calls", "Total intl charge", "Customer service calls", 
    "Churn")))
我修改了我的代码如下。我现在没有错误,但apriori算法没有发现任何规则:

    require(arules)
    #require(arulesViz)
    my_matrix= as(knime.in,"matrix");
    my_rows= nrow(my_matrix);
    my_cols= ncol(my_matrix);
    my_matrix = append(my_matrix[,4:5], my_matrix[,20])
    my_matrix <- array(my_matrix, dim=c(my_rows, 3))
    head(my_matrix, 2)
    my_cols = 3
    my_dedup_matrix= matrix(nrow=my_rows, ncol=my_cols);
    for (i in 1:my_rows) {
        m = my_matrix[i,];
        my_unique= unique(m);
        for (j in 1:my_cols) {
            my_dedup_matrix[i,j] = my_unique[j];
        }
    }
    my_new_data= apply(my_dedup_matrix, 1, function(x) x[!is.na(x)]);
    my_transactions = as(as.list(my_new_data), "transactions");
    summary(my_transactions)



## Mine association rules.
rules = apriori(my_transactions, parameter = list(supp= 0.1, conf= 0.8, target = "rules"));
summary(rules); # no rules found
inspect(rules); # no rules found
#inspect(rules[1:10])
require(阿鲁莱斯)
#要求(阿鲁莱斯维兹)
my_matrix=as(knime.in,“matrix”);
my_rows=nrow(my_矩阵);
my_cols=ncol(my_矩阵);
my_matrix=追加(my_matrix[,4:5],my_matrix[,20])

my_矩阵您需要首先将my_矩阵转换为列表。
as(as.list(我的矩阵),“交易”)
然而,我得到了一个不同的错误

as(as.list(matrix_temp),"transactions")
transactions in sparse format with
 15 transactions (rows) and
 5 items (columns)

这里有点不对劲。你说有些柱子是双倍的。你能在R节点之前转到Knime节点,并对第二个选项卡(显示域的选项卡)进行截图吗?你的信心很高。将其设置为零,然后慢慢增加,直到找到一组合理的规则。我已经将置信度设置为0.1,但是我得到了如下规则:{}=>{noVmail}。这基本上意味着在10%的情况下,有noVmail。这是一条非常有效的规则。我认为这不再是一个技术问题,而只是一个如何使用先验的问题。调整支持和信心确实有点棘手。在这里帮忙需要你有完整的数据集。是的,你是对的。非常感谢你。谁知道我在另一个账户上提交的类似问题将如何结束?你的原始代码是‘my_transactions=as(my_matrix,“transactions”)`我在asMethod(object)中得到
错误:矩阵不是逻辑矩阵或数字0-1矩阵我现在没有错误。我已经按照你的技巧修改了我的代码,你可以在我编辑的问题中看到。然而,apriori alghoritm没有给我任何规则。我认为最好是排除答案,提出一个新问题。我的答案现在悬而未决。在上面添加了一条评论。有点奇怪:我曾尝试使用knime Box获取规则,但我得到了更多的规则