Java,Weka:NaiveBayesUpdateable:无法处理数字类

时间:2013-04-11 18:50:16

标签: java weka bayesian

我正在尝试使用Weka的NaiveBayesUpdateable分类器。我的数据包含名义和数字属性:

  @relation cars
  @attribute country {FR, UK, ...}
  @attribute city {London, Paris, ...}
  @attribute car_make {Toyota, BMW, ...}
  @attribute price numeric   %% car price 
  @attribute sales numeric   %% number of cars sold

我需要根据其他属性预测销售数量(数字!)。我跑的时候:

    // Train classifier
    ArffLoader loader = new ArffLoader();
    loader.setFile(new File(trainFileName));
    Instances structure = loader.getStructure();
    structure.setClassIndex(structure.numAttributes() - 1);

    // train NaiveBayes
    NaiveBayesUpdateable nb = new NaiveBayesUpdateable();
    nb.setUseKernelEstimator(true);
    nb.buildClassifier(structure);

我得到例外:

  Exception in thread "main" weka.core.UnsupportedAttributeTypeException: weka.classifiers.bayes.NaiveBayesUpdateable: Cannot handle numeric class!
      at weka.core.Capabilities.test(Capabilities.java:954)
      at weka.core.Capabilities.test(Capabilities.java:1110)
      at weka.core.Capabilities.test(Capabilities.java:1023)
      at weka.core.Capabilities.testWithFail(Capabilities.java:1302)
      at weka.classifiers.bayes.NaiveBayes.buildClassifier(NaiveBayes.java:213)
      at foo.bar.IncrementalClassifier.trainEvalPredict(IncrementalClassifier.java:65)
      at foo.bar.IncrementalClassifier.main(IncrementalClassifier.java:36)

如何在Weka中使用数字属性进行贝叶斯分类?

1 个答案:

答案 0 :(得分:1)

您不能在Weka中使用贝叶斯分类器进行数值预测。他们都不支持这个。

相关问题