本文整理汇总了Java中de.bwaldvogel.liblinear.Model.load方法的典型用法代码示例。如果您正苦于以下问题:Java Model.load方法的具体用法?Java Model.load怎么用?Java Model.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.bwaldvogel.liblinear.Model
的用法示例。
在下文中一共展示了Model.load方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateSvm
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
public double[] evaluateSvm() throws Exception{
int right=0;
Model model = Model.load(modelFile);
for(int t=0;t<test;t++){
double prediction = Linear.predict(model, vectest[t]);
if(prediction==testattr[t]){
right++;
}
}
double precision=(double)right/test;
System.err.println("*************Precision = "+precision*100+"%*************");
double storeResult[]=new double[3];
storeResult[0]=right;
storeResult[1]=test;
storeResult[2]=precision;
return storeResult;
}
示例2: loadModels
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
/**
* Load models and feature indexers from file
* @return
*/
public boolean loadModels()
{
try
{
loadFeatureIndexers();
labellerModel = Model.load(labellerModelFile);
identifierModel = Model.load(identifierModelFile);
}
catch (IOException ex)
{
LogInfo.error("Error opening classifier models or feature indexers.");
return false;
}
return true;
}
示例3: train
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
public static void train() throws IOException, InvalidInputDataException{
String file = "output\\svm/book_svm.svm";
Problem problem = Problem.readFromFile(new File(file),-1);
SolverType solver = SolverType.L2R_LR; // -s 0
double C = 1.0; // cost of constraints violation
double eps = 0.01; // stopping criteria
Parameter parameter = new Parameter(solver, C, eps);
Model model = Linear.train(problem, parameter);
File modelFile = new File("output/model");
model.save(modelFile);
System.out.println(modelFile.getAbsolutePath());
// load model or use it directly
model = Model.load(modelFile);
Feature[] instance = { new FeatureNode(1, 4), new FeatureNode(2, 2) };
double prediction = Linear.predict(model, instance);
System.out.println(prediction);
int nr_fold = 10;
double[] target = new double[problem.l];
Linear.crossValidation(problem, parameter, nr_fold, target);
}
示例4: LibLinearModel
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
public LibLinearModel(String modelFile){
try {
model = Model.load(new File(modelFile));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例5: initialize
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
@Override
public void initialize(Parameters params) throws ResourceInitializationException {
super.initialize(params);
try {
model = Model.load(((ResourceReader) params.get(Constants.MODEL)).getReader());
} catch (IOException e) {
throw new ResourceInitializationException("Failed to load SVM model.", e);
}
labelIndeces = new int[labels.size()];
labelIndeces = model.getLabels();
representer = (TextRepresenter) params.get(Constants.REPRESENTER);
}
示例6: loadModel
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
private void loadModel() {
logger.info("Loading prediction model");
try {
if (libLinear) {
File model_file = new File(modelFile);
libLinearModel = Model.load(model_file);
} else if (rankLib) {
RankerFactory rFact = new RankerFactory();
rankLibModel = rFact.loadRanker(modelFile);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: unpackageClassifier
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
@Override
protected void unpackageClassifier(JarInputStream modelStream) throws IOException {
super.unpackageClassifier(modelStream);
JarStreams.getNextJarEntry(modelStream, this.getModelName());
this.model = Model.load(new InputStreamReader(modelStream));
}
示例8: classify
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
public static void classify(String modelfile) throws IOException{
Model model = Model.load(new File(modelfile));
}