I am trying to create a association using apriori algorithm.The data contains around 33000 records.Below is the sample of the data
id code
1 19
1 58
1 111
2 19
2 111
2 167
3 12
3 79
3 85
4 96
5 19
6 58
7 12
7 18
7 40
7 48
7 85
7 86
7 135
In R this data is:
structure(list(id = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7,
7, 7, 7, 7, 7, 7), code = c(19, 58, 111, 19, 111, 167, 12, 79,
85, 96, 19, 58, 12, 18, 40, 48, 85, 86, 135)), .Names = c("id",
"code"), row.names = c(NA, -19L), class = "data.frame")
Using the following code I tried to build the association
# creating a string of codes based on the id
library(dplyr)
Asso2 = Asso %>%
group_by(patient_id) %>%
summarise(hi = toString(hcc_id))
# converting into transactions
library(arules)
fact <- data.frame(lapply(Asso2,as.factor))
trans <- as(fact, 'transactions')
# Applying aprior
rules = apriori(trans, parameter = list(supp = 0.001, conf = 0.001,target = "rules"))
rules
inspect(rules)
I am getting totally 96 rules like below with empty lhs and I trying to understand whether we cannot make any rules from this data or am I missing anything here. Since I am novice in this, I would like to get some help.
# lhs rhs support confidence lift
# 1 {} => {hi=19, 96, 108} 0.001021696 0.001021696 1
# 2 {} => {hi=176} 0.001021696 0.001021696 1
# 3 {} => {hi=88, 108} 0.001021696 0.001021696 1
# 4 {} => {hi=72} 0.001051746 0.001051746 1
# 5 {} => {hi=88, 96} 0.001051746 0.001051746 1
# 6 {} => {hi=108, 112} 0.001081796 0.001081796 1
# 7 {} => {hi=84} 0.001081796 0.001081796 1
# 8 {} => {hi=100, 103} 0.001111846 0.001111846 1
# 9 {} => {hi=18, 108, 111} 0.001111846 0.001111846 1