-1

我在 Weka 上做这个简单的实验。我试图做简单的交叉验证,我得到了这个错误。以下是从输出生成的错误消息。

java.lang.ClassCastException: java.lang.Integer cannot be cast to weka.classifiers.evaluation.output.prediction.AbstractOutput
at weka.classifiers.Evaluation.evaluateModel(Evaluation.java:1471)
at assg.Assg.crossValidation(Assg.java:171)
at assg.Assg.main(Assg.java:160)

下面是我的编码

public static void crossValidation() throws Exception
{
    eval.evaluateModel(cls, training, 10, new Random(1));
    System.out.println(eval.toSummaryString());
}
4

1 回答 1

0

您是否阅读过错误消息和您正在调用的函数的文档?

  /**
   * Evaluates the classifier on a given set of instances. Note that
   * the data must have exactly the same format (e.g. order of
   * attributes) as the data used to train the classifier! Otherwise
   * the results will generally be meaningless.
   *
   * @param classifier machine learning classifier
   * @param data set of test instances for evaluation
   * @param forPredictionsPrinting varargs parameter that, if supplied, is
   * expected to hold a weka.classifiers.evaluation.output.prediction.AbstractOutput
   * object
   * @return the predictions
   * @throws Exception if model could not be evaluated
   * successfully
   */
  public double[] evaluateModel(Classifier classifier,
                                Instances data,
                                Object... forPredictionsPrinting) 

您将原始 int (自动装箱到java.lang.Integer)作为参数传递给期望weka.classifiers.evaluation.output.prediction.AbstractOutput. 由于类型不兼容,您显然会遇到转换错误。

于 2013-04-18T16:43:40.623 回答