Java中的Weka-如何获得IBk、KStar或LWL或
我在stackoverflow和google上搜索了所有这些条件,但没有找到IBk、KStar或LWL。我需要这三个分类工具中的任何一个的一个实例预测。我正在Android studio中进行这项工作 我找到了从其他分类器获得预测的方法,如: 对于J48:来自 对于朴素贝叶斯:来自 但是我不能使用它们,因为我的分类器没有相同的方法……或者我找不到方法 我的代码:Java中的Weka-如何获得IBk、KStar或LWL或,java,weka,predict,Java,Weka,Predict,我在stackoverflow和google上搜索了所有这些条件,但没有找到IBk、KStar或LWL。我需要这三个分类工具中的任何一个的一个实例预测。我正在Android studio中进行这项工作 我找到了从其他分类器获得预测的方法,如: 对于J48:来自 对于朴素贝叶斯:来自 但是我不能使用它们,因为我的分类器没有相同的方法……或者我找不到方法 我的代码: //I skipped code till here because its too much, //but Data is defi
//I skipped code till here because its too much,
//but Data is definetly inside *instances* (I checked with debuger)
instances.setClassIndex(instances.numAttributes()-1);
//was trying the sam with KStar, LWL, AdditiveRegression, RandomCommittee)
IBk ibk = new IBk();
//I want predicitons for this instance. For the third attribute3
Instance testInst = new DenseInstance(3);
testInst.setValue(attribute1, 3);
testInst.setValue(attribute2, 16);
testInst.setValue(attribute3, 0);
//I was hopping for some simple way like this: (but this returns nothing)
double rez =0;
String var="";
try{
ibk.buildClassifier(instances);
rez = ibk.classifyInstance(testInst);
}
catch(Exception ex)
{
Log.e("Error","ex.getMessage()");
}
}
Log.w("GIMME RESULTS:",rez);
即使是其他分类器也可以,如AdditiveRegression、Bagging、RandomCommittee和DecisionTable——它们在Weka GUI中可以做出很好的预测,但我需要Java中的预测……) 通过测试所有方法找到了它
ibk.buildClassifier(dataSet);
rez2 = ibk.distributionForInstance(i2); //distrib
int result = (int)rez3[0];
//it goes tha same with Kstar
认识到weka中的分类器通常使用离散数据运行(从最小到最大的步骤相等)。我的数据并非都是离散的。Ibk和Kstar能够使用分布式数据,这就是为什么我只能在数据中使用这两个
NaiveBayes naiveBayes = new NaiveBayes();
naiveBayes.buildClassifier(train);
// this does the trick
double label = naiveBayes.classifyInstance(test.instance(0));
test.instance(0).setClassValue(label);
System.out.println(test.instance(0).stringValue(4));
//I skipped code till here because its too much,
//but Data is definetly inside *instances* (I checked with debuger)
instances.setClassIndex(instances.numAttributes()-1);
//was trying the sam with KStar, LWL, AdditiveRegression, RandomCommittee)
IBk ibk = new IBk();
//I want predicitons for this instance. For the third attribute3
Instance testInst = new DenseInstance(3);
testInst.setValue(attribute1, 3);
testInst.setValue(attribute2, 16);
testInst.setValue(attribute3, 0);
//I was hopping for some simple way like this: (but this returns nothing)
double rez =0;
String var="";
try{
ibk.buildClassifier(instances);
rez = ibk.classifyInstance(testInst);
}
catch(Exception ex)
{
Log.e("Error","ex.getMessage()");
}
}
Log.w("GIMME RESULTS:",rez);
ibk.buildClassifier(dataSet);
rez2 = ibk.distributionForInstance(i2); //distrib
int result = (int)rez3[0];
//it goes tha same with Kstar