我有一个很大的数据集,我正在尝试挖掘变量之间的关联规则。
我的问题是,我有160个变量,其中我必须寻找关联规则,我也有超过1800项集。
此外,我的变量是连续变量。对于关联规则的挖掘,我通常采用的是先验算法,但众所周知,这种算法需要使用分类变量。
有人对我在这种情况下可以使用哪种算法有任何建议吗?
“我的数据集”的一个受限示例如下:
ID_Order Model ordered quantity
A.1 typeX 20
A.1 typeZ 10
A.1 typeY 5
B.2 typeX 16
B.2 typeW 12
C.3 typeZ 1
D.4 typeX 8
D.4 typeG 4
...我的目标是挖掘关联规则和不同产品之间的关联,也许使用R中的神经网络算法,有人对如何解决这个问题有什么建议吗?
提前感谢
发布于 2017-11-08 12:27:45
您可以像这样从数据集中创建事务:
library(dplyr)此函数用于获取每个ID_Order的事务。
concat <- function(x) {
return(list(as.character(x)))
}df组采用ID_Order和级联法。pull()返回列表中的级联Model。
a_list <- df %>%
group_by(ID_Order) %>%
summarise(concat = concat(Model)) %>%
pull(concat)将名称设置为ID_Order:
names(a_list) <- unique(df$ID_Order)然后您可以使用包arules。
获取transactions类的对象:
transactions <- as(a_list, "transactions")提取规则。您可以在supp和conf resp中设置最小的支持和最小的信任。
rules <- apriori(transactions,
parameter = list(supp = 0.1, conf = 0.5, target = "rules"))要检查规则,请使用:
inspect(rules)这就是你得到的
lhs rhs support confidence lift count
[1] {} => {typeZ} 0.50 0.50 1.0000000 2
[2] {} => {typeX} 0.75 0.75 1.0000000 3
[3] {typeW} => {typeX} 0.25 1.00 1.3333333 1
[4] {typeG} => {typeX} 0.25 1.00 1.3333333 1
[5] {typeY} => {typeZ} 0.25 1.00 2.0000000 1
[6] {typeZ} => {typeY} 0.25 0.50 2.0000000 1
[7] {typeY} => {typeX} 0.25 1.00 1.3333333 1
[8] {typeZ} => {typeX} 0.25 0.50 0.6666667 1
[9] {typeY,typeZ} => {typeX} 0.25 1.00 1.3333333 1
[10] {typeX,typeY} => {typeZ} 0.25 1.00 2.0000000 1
[11] {typeX,typeZ} => {typeY} 0.25 1.00 4.0000000 1发布于 2017-11-10 05:08:30
来自? transactions的示例部分
## example 4: creating transactions from a data.frame with
## transaction IDs and items (by converting it into a list of transactions first)
a_df3 <- data.frame(
TID = c(1,1,2,2,2,3),
item=c("a","b","a","b","c","b")
)
a_df3
trans4 <- as(split(a_df3[,"item"], a_df3[,"TID"]), "transactions")
trans4
inspect(trans4)https://stackoverflow.com/questions/47178356
复制相似问题