本文介绍了Java,Weka:NaiveBayesUpdateable:无法处理数字类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我得到异常:

  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中将数字属性用于贝叶斯分类?

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

推荐答案

您不能将Weka中的Bayes分类器用于数值预测.他们都不支持.

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

这篇关于Java,Weka:NaiveBayesUpdateable:无法处理数字类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:43