1

I have a given dataset about the orders of a store.

| Order.ID | Category | Sub.Category | Product.Name | | --------------- | -------- | ------------ | ------------ | | 1 | 2 | Furnishings | ProductName1 | | 2 | 1 | Appliances | ProductName2 | | 3 | 2 | Furnishings | ProductName3 | | 2 | 1 | Furnishings | ProductName4 | | 4 | 2 | Furnishings | ProductName5 | | 4 | 1 | Appliances | ProductName6 | | 3 | 2 | Machines | ProductName7 | | 3 | 1 | Furnishings | ProductName8 | ...

The Order.ID determines which rowes belong to the same order.

Now I want to do some association rule mining with R for this dataset by using the 'arules' package.

My code until now looks like this:

# format columns
storeData$Order.ID     <- as.factor(storeData$Order.ID)
storeData$Category     <- as.factor(storeData$Category)
storeData$Sub.Category <- as.factor(storeData$Sub.Category)
storeData$Product.Name <- as.factor(storeData$Product.Name)

# create a transaction matrix
transactions <- as(split(storeData[, "Product.Name"], 
                    storeData$Order.ID), "transactions")

# association rules
association_rules <- apriori(transactions, 
    parameter = list(support=0.0001, confidence=0.2))

First question: How do I create contingency tables for the rules? Or just one contingency table for a selected rule.

Second question: Now I also want to do some multilevel association rule mining by the categories and sub-categories, but I do not know how I can do this. I know that the 'arules' package has some functions to achieve this but I do not know how to use them.

Does anyone know how to mine for multilevel association rules with R by using the 'arules' package?

justAUser
  • 11
  • 4

0 Answers0