【问题标题】:The type FastVector<E> is deprecated不推荐使用 FastVector<E> 类型
【发布时间】:2015-01-08 18:45:33
【问题描述】:

我正在尝试从 Java 中的多维数组中获取 arrf 扩展输出文件。我导入了 weka 库,但是我得到了一个错误; The type FastVector&lt;E&gt; is deprecated.

我可以使用什么来代替 FastVector 以及如何重写下面的代码?

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

【问题讨论】:

    标签: java weka arff


    【解决方案1】:

    Weka 现在在大多数地方都使用类型化的 ArrayList。您可以为此使用ArrayList&lt;Attribute&gt;:

    ArrayList<Attribute> atts = new ArrayList<Attribute>();
        for (int att = 0; att < numAtts; att++) {
            atts.add(new Attribute("Attribute" + att, att));
        }
    

    【讨论】:

    • 是的,我明白了,但是如何在上面的代码中使用 ArrayList?
    • 我用代码 sn-p 编辑了我的回复。它应该像更改 atts 变量的类型一样简单。
    • 但是,Instance类型的实例化问题仍在进行中。你对这个错误有什么想法吗?
    • @EngineerEngin Instance 是一个接口。您不能直接创建接口的实例,但可以创建实现的实例。例如,SparseInstance。
    • 那么,如何重写我的代码呢?我尝试使用 DenseInstance 但出现错误:Instances dataset = new DenseInstance("Dataset", atts, numInstances);
    猜你喜欢
    • 2018-05-13
    • 1970-01-01
    • 2022-08-09
    • 2019-02-07
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 2023-03-09
    相关资源
    最近更新 更多