我从来没有用过R,但现在我需要导入一个稀疏矩阵来在R中做关联规则
我的导入数据是这样的稀疏矩阵:
i j x
1 2 3 1
2 3 5 1
3 3 1 1
4 2 5 1
. . . .
. . . .
200000000 . . .
稀疏矩阵大小为200,000,000 X 3, 矩阵是200000 X 100000(大数据?)
我想用这些数据在 R 中做关联规则,
是否使用 'Package arules' itemMatrix-class & tidLists-class() ?还是其他人?
怎么办?
我喜欢这个,但不工作:
channel <- odbcConnect("test")
data<-sqlQuery(channel,"select i,j,x from table") # it's work
(args <- data.frame(data)) # it's work ,print sparse matrix
# i j x
#1 2 3 1
#2 3 5 1
#3 3 1 1
#3 2 5 1
# ....
(Aa <- do.call(sparseMatrix, args)) # it's work ,print sparse Matrix of class "dgCMatrix"
# 200000 X 100000 sparse Matrix of class "dgCMatrix"
# 1 2 3 4 5....
# [1,] . . . . .
# [2,] . . | . |
# [3,] | . . . |
# ....
rules <- apriori(Aa) # it's not work
Error in as(data, "transactions") :
no method or default for coercing “dgCMatrix” to “transactions”
可以在先验函数中使用稀疏矩阵吗?
也许我使用了错误的包?
我需要稀疏矩阵->矩阵->关联规则吗?
还是稀疏矩阵->关联规则?
最佳答案
导入i,j:
library(RODBC)
library(arulse)
channel <- odbcConnect("DB", uid="XXXX", pwd="XXXX")
data<-sqlQuery(channel,"select distinct i as TID,j as item from table")
trans <- as(split(data[,"item"], data[,"TID"]), "transactions") # add this
rules <- apriori(trans)
关于r - 可以导入稀疏矩阵在R中做关联规则吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16324110/