0

I have my application which need to get associations via the Apriori Algorithm. In order to achieve results I use Weka dependency. Though I want to get associations it prints memory locations. I have attached the output as well. Thanks.

Here is my code:

public class App 
{
    static Logger log = Logger.getLogger(App.class.getName());
    public static BufferedReader readDataFile(String filename) {
        BufferedReader inputReader = null;

        try {
            inputReader = new BufferedReader(new FileReader(filename));
        } catch (FileNotFoundException ex) {
        }
        return inputReader;
    }
    public static void main( String[] args ) throws Exception {
        //Define ArrayList to Add Clustered Information
        ArrayList<FastVector[]> associationInfoArrayList = new ArrayList<FastVector[]>();
        Apriori apriori = new Apriori();
        apriori.setNumRules(15);
        BufferedReader datafile = readDataFile("/media/jingi_ingi/IR1_CPRA_X6/Documents/ss.arff");
        Instances data = new Instances(datafile);
        //   Instances instances = new Instances(datafile);
        apriori.buildAssociations(data);
        log.debug("Testing Apriori Algo Results Started ....");
        log.debug("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-");
        log.debug("Number of Associations : " + apriori.getNumRules());
        log.debug("Adding Association Information to ArrayList ..");

        Object objectArrayOfAssociations[] = new Object[apriori.getNumRules()];
                        log.debug(apriori.getAllTheRules().toString());

       for(int i=0; i<apriori.getNumRules(); i++) {
            objectArrayOfAssociations[i] = apriori.getAllTheRules();
            log.debug("Associations Discovered : " + objectArrayOfAssociations[i].toString());
        }
    }
}

Output of the Application:

2015-04-05 20:16:42 DEBUG App:48 - Associations Discovered : [Lweka.core.FastVector;@19a96bae

2015-04-05 20:16:42 DEBUG App:48 - Associations Discovered : [Lweka.core.FastVector;@19a96bae

2015-04-05 20:16:42 DEBUG App:48 - Associations Discovered : [Lweka.core.FastVector;@19a96bae

2015-04-05 20:16:42 DEBUG App:48 - Associations Discovered : [Lweka.core.FastVector;@19a96bae

Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51

1 Answers1

1
apriori.getAllTheRules() 

returns an Array of FastVectors, but FastVector doesn't have a toString() method to dump its contents as implied by your intentions. You can extend FastVector and add your own toString() or write a little helper method to dump the contents as desired. Here's an example

Something like:

for(FastVector fastVector : apriori.getAllTheRules())  
  log.debug(fastVector.getRevision()); 
// or whichever attribute you want to show
Community
  • 1
  • 1
belwood
  • 3,320
  • 11
  • 38
  • 45
  • I dont get your point @belwood. Could you please tell me it in more detail ? – Du-Lacoste Apr 05 '15 at 15:55
  • The default toString() method in an Java object displays the object class and its hash code e.g. from your output: [Lweka.core.FastVector;@19a96bae So look at the example link I provided to add code to print the contents of the array. – belwood Apr 05 '15 at 15:58
  • ok i see your point. :) but by checking your link did not alert me. Could you please give me solution. I have been searching this for more than one day now – Du-Lacoste Apr 05 '15 at 16:00