许多连续变量之间的关联规则
Association rules between many continuous variables
我有一个大数据集,我正在尝试挖掘变量之间的关联规则。
我的问题是我有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 中的神经网络算法 有人对如何解决这个问题有任何建议吗?
提前致谢
您可以像这样从您的数据集创建交易:
library(dplyr)
此函数用于获取每个 ID_Order
的交易
concat <- function(x) {
return(list(as.character(x)))
}
按 ID_Order
分组 df
并连接。 pull()
returns 列表中串联的 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
的对象class:
transactions <- as(a_list, "transactions")
提取规则。您可以分别在 supp
和 conf
中设置最小支持度和最小置信度。
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
来自 ? 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)
我有一个大数据集,我正在尝试挖掘变量之间的关联规则。
我的问题是我有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 中的神经网络算法 有人对如何解决这个问题有任何建议吗?
提前致谢
您可以像这样从您的数据集创建交易:
library(dplyr)
此函数用于获取每个 ID_Order
concat <- function(x) {
return(list(as.character(x)))
}
按 ID_Order
分组 df
并连接。 pull()
returns 列表中串联的 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
的对象class:
transactions <- as(a_list, "transactions")
提取规则。您可以分别在 supp
和 conf
中设置最小支持度和最小置信度。
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
来自 ? 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)