Transforming data into transactions
Before using any rule mining algorithm, we need to transform data from the data frame format into transactions. In this example, we demonstrate how to transform a purchase order dataset into transactions with the arules
package.
Getting ready
Download the purchase_order.RData
dataset from the https://github.com/ywchiu/rcookbook/raw/master/chapter9/product_by_user.RData GitHub link.
How to do it…
Perform the following steps to create transactions:
First, install and load the
arules
package:> install.packages("arules") > library(arules)
Use the
load
function to load purchase orders by user into an R session:> load("product_by_user.RData")
Last, convert the
data.table
(ordata.frame
) into transactions with theas
function:> trans = as(product_by_user $Product, "transactions") > trans transactions in sparse format with 32539 transactions (rows) and 20054 items (columns)
How it works…
Before mining a frequent item set or association rule, it is...