我想将产品名称分类为以下几类:
我找到了使用Classifier4J的BayesianClassifer的好方法。我尝试编写一些原型,但是在使用Classifier4J的BayesianClassifer时遇到了异常。
Exception in thread "main" java.lang.IllegalArgumentException: Word Data Source does not support non-default categories.
at net.sf.classifier4J.bayesian.BayesianClassifier.checkCategoriesSupported(BayesianClassifier.java:354)
at net.sf.classifier4J.bayesian.BayesianClassifier.teachMatch(BayesianClassifier.java:180)
at classification.Application.main(Application.java:23)
我刚刚向分类器添加了一些Matches和NonMachtes,但是我找不到添加类别的方法,因为该异常表明它不支持非默认类别。
IWordsDataSource wds = new SimpleWordsDataSource();
BayesianClassifier classifier1 = new BayesianClassifier(wds);
classifier1.teachMatch("VEGAN","Sonnenblumenkerne");
classifier1.teachMatch("VEGAN","Kerne");
classifier1.teachMatch("VEGAN","Cashew");
classifier1.teachMatch("VEGAN","Mandeln");
classifier1.teachMatch("VEGAN","Sonnenblumenkerne");
classifier1.teachMatch("OMNIVORE","Rind");
classifier1.teachMatch("OMNIVORE","Huhn");
classifier1.teachMatch("OMNIVORE","Fleisch");
classifier1.teachMatch("OMNIVORE","Speck");
classifier1.teachMatch("OMNIVORE","Pute");
classifier1.teachMatch("VEGETARIAN","GEMÜSE");
classifier1.teachMatch("VEGETARIAN","Milch");
classifier1.teachMatch("VEGETARIAN","Ei");
classifier1.teachMatch("VEGETARIAN","Soja");
classifier1.teachNonMatch("VEGAN","Rind");
classifier1.teachNonMatch("VEGAN","Huhn");
classifier1.teachNonMatch("VEGAN","Fleisch");
classifier1.teachNonMatch("VEGAN","Speck");
classifier1.teachNonMatch("VEGAN","Pute");
classifier1.teachNonMatch("VEGAN","GEMÜSE");
classifier1.teachNonMatch("VEGAN","Milch");
classifier1.teachNonMatch("VEGAN","Ei");
classifier1.teachNonMatch("VEGAN","Soja");
System.out.println("MAtches = " + classifier1.classify("VEGAN","GEMÜSE"));
我错过了一些东西,或者我读了一些重要的东西。