我正在尝试使用 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 中使用数字属性进行贝叶斯分类?