Before going into the details of affinity analysis, we will first understand the types of datasets that will be used for the affinity analysis to extract patterns on the co-occurrence of events.
First, let's understand the built-in AdultUCI
dataset, which comes with the arules
package. The data is in the data frame format, so we will see how to convert this into a transactional dataset:
library(arules)
This package is required in order to perform affinity analysis using R. Now, let's load the dataset that comes along with this package:
data("AdultUCI") class(AdultUCI) [1] "data.frame"
As you can see in the preceding output, the dataset is in the format of a data frame. We need to convert the AdultUCI
dataset into a transactional dataset. Before converting, we will see the attributes present in the dataset using the head
function, which will display the top five rows by default:
head(AdultUCI)
The output of the preceding command is as follows...