당신은 다음과 같은 데이터 집합에서 트랜잭션을 생성 할 수 있습니다
:
이 기능은
ID_Order
에 의해 그룹
df
ID_Order
concat <- function(x) {
return(list(as.character(x)))
}
당 트랜잭션을 가져 오는 데 사용됩니다
library(dplyr)
및 사슬 같이 잇다. pull()
은 연결 된 Model
을 목록에 반환합니다. ID_Order
에
a_list <- df %>%
group_by(ID_Order) %>%
summarise(concat = concat(Model)) %>%
pull(concat)
설정 이름 : transactions
클래스의
가져 오기 개체 :
transactions <- as(a_list, "transactions")
추출 규칙
names(a_list) <- unique(df$ID_Order)
그런 다음 패키지
arules
를 사용할 수 있습니다.
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
보기 [ arules] (https://cran.r-project.org/web/packages/arules/index.ht) ml) – mtoto