当前位置: 首页>>代码示例>>Java>>正文


Java Linear.predict方法代码示例

本文整理汇总了Java中de.bwaldvogel.liblinear.Linear.predict方法的典型用法代码示例。如果您正苦于以下问题:Java Linear.predict方法的具体用法?Java Linear.predict怎么用?Java Linear.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在de.bwaldvogel.liblinear.Linear的用法示例。


在下文中一共展示了Linear.predict方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evaluateSvm

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的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;
}
 
开发者ID:thunlp,项目名称:MMDW,代码行数:18,代码来源:Evaluate_SVM.java

示例2: predictOne

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
public Matrix predictOne(Feature[] x) {
	Matrix result = null;
	if (model.isProbabilityModel()) {
		double[] probabilities = new double[model.getNrClass()];
		Linear.predictProbability(model, x, probabilities);
		result = Matrix.Factory.zeros(1, model.getNrClass());
		for (int i = 0; i < probabilities.length; i++) {
			int label = model.getLabels()[i];
			result.setAsDouble(probabilities[i], 0, label);
		}
	} else {
		double classId = Linear.predict(model, x);
		result = Matrix.Factory.zeros(1, Math.max(model.getNrClass(), (int) (classId + 1)));
		result.setAsDouble(1.0, 0, (int) classId);
	}

	return result;
}
 
开发者ID:jdmp,项目名称:java-data-mining-package,代码行数:19,代码来源:LibLinearClassifier.java

示例3: train

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的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);
}
 
开发者ID:laozhaokun,项目名称:sentimentclassify,代码行数:24,代码来源:Main.java

示例4: predict2

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
@Deprecated
public static int[] predict2(Model model, Feature[][] data, int[] labels) {

	int N = data.length;
	int[] pre_label = new int[N];

	for ( int i = 0; i < N; i ++ ) {
		pre_label[i] = Linear.predict(model, data[i]);
	}

	if (labels != null) {
		int cnt_correct = 0;
		for ( int i = 0; i < N; i ++ ) {
			if ( pre_label[i] == labels[i] )
				cnt_correct ++;
		}
		double accuracy = (double)cnt_correct / (double)N;
		System.out.println(String.format("Accuracy: %.2f%%\n", accuracy * 100));
	}

	return pre_label;

}
 
开发者ID:MingjieQian,项目名称:JML,代码行数:24,代码来源:MultiClassSVM.java

示例5: getLabel

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
@Override
public String getLabel(JCas cas) {
    Vector<Feature[]> instanceFeatures = applyFeatures(cas, features);
    Feature[] instance = combineInstanceFeatures(instanceFeatures);
    probEstimates = new double[model.getNrClass()];
    Double prediction;
    if (model.getSolverType().isLogisticRegressionSolver()) {
        prediction = Linear.predictProbability(model, instance, probEstimates);
        score = probEstimates[prediction.intValue()];
    } else {
        prediction = Linear.predict(model, instance);
    }
    label = labelMappings.get(prediction);
    return label;
}
 
开发者ID:uhh-lt,项目名称:LT-ABSA,代码行数:16,代码来源:LinearClassifier.java

示例6: performPrediction

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
@Override
public ExampleSet performPrediction(ExampleSet exampleSet, Attribute predictedLabel) throws OperatorException {
	FastExample2SparseTransform ripper = new FastExample2SparseTransform(exampleSet);
	Attribute label = getLabel();

	Attribute[] confidenceAttributes = null;
	if (label.isNominal() && label.getMapping().size() >= 2) {
		confidenceAttributes = new Attribute[linearModel.label.length];
		for (int j = 0; j < linearModel.label.length; j++) {
			String labelName = label.getMapping().mapIndex(linearModel.label[j]);
			confidenceAttributes[j] = exampleSet.getAttributes()
					.getSpecial(Attributes.CONFIDENCE_NAME + "_" + labelName);
		}
	}

	Iterator<Example> i = exampleSet.iterator();
	while (i.hasNext()) {
		Example e = i.next();

		// set prediction
		FeatureNode[] currentNodes = FastLargeMargin.makeNodes(e, ripper, this.useBias);

		double predictedClass = Linear.predict(linearModel, currentNodes);
		e.setValue(predictedLabel, predictedClass);

		// use simple calculation for binary cases...
		if (label.getMapping().size() == 2) {
			double[] functionValues = new double[linearModel.nr_class];
			Linear.predictValues(linearModel, currentNodes, functionValues);
			double prediction = functionValues[0];
			if (confidenceAttributes != null && confidenceAttributes.length > 0) {
				e.setValue(confidenceAttributes[0], 1.0d / (1.0d + java.lang.Math.exp(-prediction)));
				if (confidenceAttributes.length > 1) {
					e.setValue(confidenceAttributes[1], 1.0d / (1.0d + java.lang.Math.exp(prediction)));
				}
			}
		}

	}
	return exampleSet;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:42,代码来源:FastMarginModel.java

示例7: predictScore

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
public double predictScore(FeaturePack<T> fp, FeatureNormalizer fn) {
	return Linear.predict(model, featureMapToFeatures(fn.ftrToNormalizedFtrArray(fp)));
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:4,代码来源:LibLinearModel.java

示例8: classify

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
@Override
public Integer classify(SparseInstance instance) {
    Feature[] feat = getFeatureArray(instance);
    return (int) Linear.predict(model, feat);
}
 
开发者ID:clearwsd,项目名称:clearwsd,代码行数:6,代码来源:LibLinearClassifier.java

示例9: performPrediction

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
@Override
public ExampleSet performPrediction(ExampleSet exampleSet, Attribute predictedLabel) throws OperatorException {
	FastExample2SparseTransform ripper = new FastExample2SparseTransform(exampleSet);
	Attribute label = getLabel();

	Attribute[] confidenceAttributes = null;
	if (label.isNominal() && label.getMapping().size() >= 2) {
		confidenceAttributes = new Attribute[linearModel.label.length];
		for (int j = 0; j < linearModel.label.length; j++) {
			String labelName = label.getMapping().mapIndex(linearModel.label[j]);
			confidenceAttributes[j] = exampleSet.getAttributes()
					.getSpecial(Attributes.CONFIDENCE_NAME + "_" + labelName);
		}
	}

	Iterator<Example> i = exampleSet.iterator();
	OperatorProgress progress = null;
	if (getShowProgress() && getOperator() != null && getOperator().getProgress() != null) {
		progress = getOperator().getProgress();
		progress.setTotal(exampleSet.size());
	}
	int progressCounter = 0;
	while (i.hasNext()) {
		Example e = i.next();

		// set prediction
		FeatureNode[] currentNodes = FastLargeMargin.makeNodes(e, ripper, this.useBias);

		double predictedClass = Linear.predict(linearModel, currentNodes);
		e.setValue(predictedLabel, predictedClass);

		// use simple calculation for binary cases...
		if (label.getMapping().size() == 2) {
			double[] functionValues = new double[linearModel.nr_class];
			Linear.predictValues(linearModel, currentNodes, functionValues);
			double prediction = functionValues[0];
			if (confidenceAttributes != null && confidenceAttributes.length > 0) {
				e.setValue(confidenceAttributes[0], 1.0d / (1.0d + java.lang.Math.exp(-prediction)));
				if (confidenceAttributes.length > 1) {
					e.setValue(confidenceAttributes[1], 1.0d / (1.0d + java.lang.Math.exp(prediction)));
				}
			}
		}

		if (progress != null && ++progressCounter % OPERATOR_PROGRESS_STEPS == 0) {
			progress.setCompleted(progressCounter);
		}
	}
	return exampleSet;
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:51,代码来源:FastMarginModel.java

示例10: predict

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
public Integer predict(CounterInterface<Integer> toPredict) {
	return (int) Linear.predict(model, convertToFeatureNodes(toPredict));
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:4,代码来源:LibLinearWrapper.java

示例11: computePred

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
private double computePred(FeatureNode[] f) {
	double pred = 0;
	//double[] prob_estimates = new double[2];

	/*if (libLinearModel.isProbabilityModel()) {

		prob_estimates = new double[2];

		Linear.predictProbability(libLinearModel, f, prob_estimates);
		pred = prob_estimates[0];

	} else
		pred += Linear.predict(libLinearModel, f);*/
	
	pred = Linear.predict(libLinearModel, f);

	return pred;
}
 
开发者ID:sisinflab,项目名称:lodreclib,代码行数:19,代码来源:RecommenderWorker.java

示例12: classify

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
@Override
public OUTCOME_TYPE classify(List<Feature> features) throws CleartkProcessingException {
  FeatureNode[] encodedFeatures = this.featuresEncoder.encodeAll(features);
  int encodedOutcome = (int)Linear.predict(this.model, encodedFeatures);
  return this.outcomeEncoder.decode(encodedOutcome);
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:7,代码来源:GenericLibLinearClassifier.java

示例13: predict

import de.bwaldvogel.liblinear.Linear; //导入方法依赖的package包/类
public double predict(Feature[] instance, ModelType modelType)
{
    return Linear.predict(modelType == ModelType.labeller ? labellerModel : identifierModel, instance);
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:5,代码来源:ArgumentClassifier.java


注:本文中的de.bwaldvogel.liblinear.Linear.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。