7

I am trying to get arrf extended output file from a multidimensional array in Java. And I imported weka library, however I got an error; The type FastVector<E> is deprecated.

What can I use instead of FastVector and how I can rewrite the code below?

    import weka.core.FastVector; //Error: The type FastVector<E> is deprecated. 


    int [][] myArray = new int[45194][12541];

    for (int i = 0; i < myArray.length; i++) {
        for (int j = 0; j < myArray[0].length; j++) {
            System.out.print(myArray[i][j]+" "); 
        }
        System.out.println("");
    }

    int numAtts = myArray[0].length;
    FastVector atts = new FastVector(numAtts);
    for (int att = 0; att < numAtts; att++) {
        atts.addElement(new Attribute("Attribute" + att, att));
    }

    int numInstances = myArray.length;
    Instances dataset = new Instances("Dataset", atts, numInstances);
    for (int inst = 0; inst < numInstances; inst++) {
        dataset.add(new Instance(1.0, myArray[inst]));   //Error: Cannot instantiate the type Instance
    }

    BufferedWriter writer = new BufferedWriter(new FileWriter("test.arff"));
    writer.write(dataset.toString());
    writer.flush();
    writer.close();
Peter O.
  • 32,158
  • 14
  • 82
  • 96
EngineerEngin
  • 105
  • 1
  • 5

1 Answers1

15

Weka now uses typed ArrayLists most places. You can use ArrayList<Attribute> for this:

ArrayList<Attribute> atts = new ArrayList<Attribute>();
    for (int att = 0; att < numAtts; att++) {
        atts.add(new Attribute("Attribute" + att, att));
    }
Chris
  • 22,923
  • 4
  • 56
  • 50
  • 2
    Yes, I see that, but how can I use ArrayList in code above? – EngineerEngin Nov 12 '14 at 02:30
  • I edited my response with a code snippet. It should be as simple as changing the type of your atts variable. – Chris Nov 12 '14 at 02:33
  • But, the instantiate problem of the type Instance is still ongoing. Do you have any idea for that error? – EngineerEngin Nov 12 '14 at 02:54
  • @EngineerEngin `Instance` is an interface. You can't create an instance of an interface directly, but you can create an instance of the implementation. For example, `SparseInstance`. – Obicere Nov 12 '14 at 03:04
  • Well then, how can rewrite my code? I tried to use DenseInstance but got error: Instances dataset = new DenseInstance("Dataset", atts, numInstances); – EngineerEngin Nov 12 '14 at 04:24
  • try Instances dataset = new DenseInstance(numInstances); and then adding attributes one by one – Sudheera Nov 12 '14 at 06:53