java项目中怎么查看用的序列_如何在Java应用程序中使用序列化分类器对...
我想使用序列化分類器對新實例進(jìn)行分類.我找到了這堂課,但我聽不懂.
arg [2] =類屬性名稱,arg [3] =基于實例的索引(從原始數(shù)據(jù)集中進(jìn)行預(yù)測)
這是此類的代碼:
import weka.core.*;
import weka.classifiers.*;
import java.io.*;
/**
* A little class for testing deserialization and prediction.
*
* @author FracPete (fracpet at waikat dot ac dot nz)
*/
public class Blah {
/**
* Takes 4 arguments:
*
*
serialized model*
ARFF file*
class attribute name*
1-based index of an instance to predict from original dataset*
*/
public static void main(String[] args) throws Exception {
// read the arff training file
BufferedReader reader = new BufferedReader(new FileReader(args[1]));
Instances in = new Instances(reader);
in.setClass(in.attribute(args[2]));
// instance to classify
int index = Integer.parseInt(args[3]) - 1;
Instance toClassifyInstance = (Instance) in.instance(index).copy();
toClassifyInstance.setClassValue(Instance.missingValue());
// deserialize model
Classifier cls = null;
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(args[0]));
cls = (Classifier) ois.readObject();
ois.close();
// PREDICTION
double clsLabel = cls.classifyInstance(toClassifyInstance);
String classLabel = in.classAttribute().value((int) clsLabel);
System.out.println(classLabel + " =?= " + in.instance(index).stringValue(in.classIndex()));
}
}
提前致謝.
總結(jié)
以上是生活随笔為你收集整理的java项目中怎么查看用的序列_如何在Java应用程序中使用序列化分类器对...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 话费怎么提现到支付宝里
- 下一篇: java美元兑换,(Java实现) 美元