Apriori

We will use the Apriori algorithm as implemented in Weka. It iteratively reduces the minimum support until it finds the required number of rules with the given minimum confidence. We'll implement the algorithm using the following steps:

  1. We'll import the required libraries using the following lines of code:
import java.io.BufferedReader; 
import java.io.FileReader; 
import weka.core.Instances; 
import weka.associations.Apriori; 
  1. First, we'll load the supermarket.arff dataset:
Instances data = new Instances(new BufferedReader(new FileReader("data/supermarket.arff"))); 
  1. We'll initialize an Apriori instance and call the buildAssociations(Instances) function to start frequent pattern mining, as follows:
Apriori model = new Apriori(); ...

Get Machine Learning in Java - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.