我的应用程序需要通过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调试应用程序:48-发现关联:
[Lweka.core.FastVector;@19a96bae
2015-04-05 20:16:42调试应用程序:48-发现关联:
[Lweka.core.FastVector;@19a96bae
2015-04-05 20:16:42调试应用程序:48-发现关联:
[Lweka.core.FastVector;@19a96bae
2015-04-05 20:16:42调试应用程序:48-发现关联:
[lweka.core.fastvector;@19a96bae

最佳答案

apriori.getAllTheRules()

返回一个FastVectors数组,但FastVector没有toString()方法来转储意图所暗示的内容您可以扩展fastVector并添加自己的toString()或编写一个小的helper方法来根据需要转储内容。Here's an example
类似于:
for(FastVector fastVector : apriori.getAllTheRules())
  log.debug(fastVector.getRevision());
// or whichever attribute you want to show

08-29 00:38