Apriori算法给出了内存位置

时间:2015-04-05 15:30:00

标签: java algorithm weka

我的应用程序需要通过 Apriori算法获取关联。为了获得结果,我使用 Weka 依赖。虽然我想获得关联,但它会打印内存位置。我也附加了输出。感谢。

这是我的代码:

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());
        }
    }
}

申请表的输出:

  

2015-04-05 20:16:42 DEBUG App:48 - 发现的协会:   [Lweka.core.FastVector; @ 19a96bae

     

2015-04-05 20:16:42 DEBUG App:48 - 发现的协会:   [Lweka.core.FastVector; @ 19a96bae

     

2015-04-05 20:16:42 DEBUG App:48 - 发现的协会:   [Lweka.core.FastVector; @ 19a96bae

     

2015-04-05 20:16:42 DEBUG App:48 - 发现的协会:   [Lweka.core.FastVector; @ 19a96bae

1 个答案:

答案 0 :(得分:1)

apriori.getAllTheRules() 

返回一个FastVectors数组,但是FastVector没有toString()方法来转储其内容,如你的意图所暗示的那样。您可以扩展FastVector并添加自己的toString()或编写一个小帮助方法来根据需要转储内容。 Here's an example

类似的东西:

for(FastVector fastVector : apriori.getAllTheRules())  
  log.debug(fastVector.getRevision()); 
// or whichever attribute you want to show