问题
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