Simple text classification using naive bayes (weka) in java

穿精又带淫゛_ 提交于 2019-12-05 07:32:22
xro7

Your code seems fine, though i have two comments to make.

  • First, you set filter's format with this command filter.setInputFormat(train); so as to use this filter and make test and train data compatible. You should not change the format again with this command: filter.setInputFormat(test); as this might create compatibility issues.
  • Also instead of getting the first attribute: train.attribute(0).value((int)index); (which seems to me that is not corresponds to class attribute) try using this command train.classAttribute().value((int)index);

P.S. Check Load naïve Bayes model in Java code using weka jar for a complete workflow and explanation of a classification example (the material was once in SO Documentation). This example is using the LibLinear classifier but the logic is the same.

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