Java, Weka: NaiveBayesUpdateable: Cannot handle numeric class

左心房为你撑大大i 提交于 2019-12-23 20:14:03

问题


I am trying to use NaiveBayesUpdateable classifier from Weka. My data contains both nominal and numeric attributes:

  @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

I need to predict the number of sales (numeric!) based on other attributes. When I run:

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

I get exception:

  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)

How can I use numeric attribute for Bayes classification in Weka?


回答1:


You can't use the Bayes classifiers in Weka for numeric predictions. None of them support this.



来源:https://stackoverflow.com/questions/15956537/java-weka-naivebayesupdateable-cannot-handle-numeric-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!