2013-04-11 58 views
3

我想从Weka使用NaiveBayesUpdateable分类器。我的数据包含名义和数字属性:Java,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

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

+0

如果我在'N'长度为'k'的区间中分割数值属性的值,我可以使用名义属性,其中'n'是一个类名,像这样:'@attribute class {1,2,3 ,...,N}'? Weka中这个'N'有多大? – 2013-04-11 19:50:05

+0

你可以和它一样大,只要你真的喜欢。请注意,在这种情况下不推荐这样做,因为您明确预测了数字量。 – 2013-04-12 08:06:01

+0

你会推荐什么算法来预测数字质量? – 2013-04-12 09:30:52