Example usage for weka.associations AprioriItemSet toString

List of usage examples for weka.associations AprioriItemSet toString

Introduction

In this page you can find the example usage for weka.associations AprioriItemSet toString.

Prototype

@Override
public final String toString(Instances instances) 

Source Link

Document

Returns the contents of an item set as a string.

Usage

From source file:demo.bean.WekaDABeanImpl.java

License:Open Source License

@Override
public Map<Integer, ResultItem> generateResults() {
    Map<Integer, ResultItem> myResults = new HashMap<Integer, ResultItem>();

    try {/*  w w w. j  a v a  2 s  .  c om*/
        InputStream input = getClass().getResourceAsStream("/arff/weather.nominal.arff");
        DataSource source = new DataSource(input);
        Instances data = source.getDataSet();

        Apriori apriori = new Apriori();
        apriori.buildAssociations(data);

        FastVector res[] = apriori.getAllTheRules();
        int x = 0;
        for (FastVector rule : res) {
            if (rule == null)
                continue;

            for (int i = 0; i < rule.size(); ++i) {
                Object o = rule.elementAt(i);

                if (o instanceof AprioriItemSet) {
                    AprioriItemSet itemSet = (AprioriItemSet) o;

                    System.out.println(itemSet.toString(data) + " " + itemSet.items().length);

                    String ruleStr = itemSet.toString(data) + " ";
                    myResults.put((x + 1), new ResultItem((x + 1), ruleStr));
                    if (x >= 10)
                        break;
                    x++;
                }
            }

        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return myResults;
}