libsvm.svm.svm_predict()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(261)

本文整理了Java中libsvm.svm.svm_predict()方法的一些代码示例,展示了svm.svm_predict()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。svm.svm_predict()方法的具体详情如下:
包路径:libsvm.svm
类名称:svm
方法名:svm_predict

svm.svm_predict介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

@Override
public double regress(FeatureVector features)
{
  requireNonNull(model, "model is null");
  return svm.svm_predict(model, toSvmNodes(features));
}

代码示例来源:origin: com.facebook.thirdparty/libsvm

public static double svm_predict_probability(svm_model model, svm_node[] x, double[] prob_estimates)
{
  if ((model.param.svm_type == svm_parameter.C_SVC || model.param.svm_type == svm_parameter.NU_SVC) &&
    model.probA!=null && model.probB!=null)
  {
    int i;
    int nr_class = model.nr_class;
    double[] dec_values = new double[nr_class*(nr_class-1)/2];
    svm_predict_values(model, x, dec_values);
    double min_prob=1e-7;
    double[][] pairwise_prob=new double[nr_class][nr_class];
    
    int k=0;
    for(i=0;i<nr_class;i++)
      for(int j=i+1;j<nr_class;j++)
      {
        pairwise_prob[i][j]=Math.min(Math.max(sigmoid_predict(dec_values[k],model.probA[k],model.probB[k]),min_prob),1-min_prob);
        pairwise_prob[j][i]=1-pairwise_prob[i][j];
        k++;
      }
    multiclass_probability(nr_class,pairwise_prob,prob_estimates);
    int prob_max_idx = 0;
    for(i=1;i<nr_class;i++)
      if(prob_estimates[i] > prob_estimates[prob_max_idx])
        prob_max_idx = i;
    return model.label[prob_max_idx];
  }
  else 
    return svm_predict(model, x);
}

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_jsre

int predictedLabel = (int) svm.svm_predict(model, x);
double[] probs = new double[x.length];
svm.svm_predict_probability(model, x, probs);

代码示例来源:origin: prestodb/presto

@Override
public Integer classify(FeatureVector features)
{
  requireNonNull(model, "model is null");
  return (int) svm.svm_predict(model, toSvmNodes(features));
}

代码示例来源:origin: eu.fbk.utils/utils-svm

@Override
LabelledVector doPredict(final boolean withProbabilities, final Vector vector) {
  final svm_node[] nodes = encodeVector(this.dictionary, vector);
  if (withProbabilities) {
    final int numLabels = getParameters().getNumLabels();
    final double[] p = new double[numLabels];
    final int label = (int) svm.svm_predict_probability(this.model, nodes, p);
    final float[] probabilities = new float[numLabels];
    for (int i = 0; i < p.length; ++i) {
      final int labelIndex = this.model.label[i];
      probabilities[labelIndex] = (float) p[i];
    }
    return vector.label(label, probabilities);
  } else {
    final int label = (int) svm.svm_predict(this.model, nodes);
    return vector.label(label);
  }
}

代码示例来源:origin: tw.edu.ntu.csie/libsvm

return svm_predict(model, x);

代码示例来源:origin: net.sourceforge/javaml

@Override
public Object classify(Instance instance) {
  svm_node[] x = convert(instance);
  double d = svm.svm_predict(model, x);
  Object out = data.classValue((int) d);
  return out;
}

代码示例来源:origin: DigitalPebble/TextClassification

int winner = (int)svm.svm_predict(model, svm_nodes);

代码示例来源:origin: jzy3d/jzy3d-api

public static double svm_predict_probability(svm_model model, svm_node[] x, double[] prob_estimates)
{
  if ((model.param.svm_type == svm_parameter.C_SVC || model.param.svm_type == svm_parameter.NU_SVC) &&
    model.probA!=null && model.probB!=null)
  {
    int i;
    int nr_class = model.nr_class;
    double[] dec_values = new double[nr_class*(nr_class-1)/2];
    svm_predict_values(model, x, dec_values);
    double min_prob=1e-7;
    double[][] pairwise_prob=new double[nr_class][nr_class];
    
    int k=0;
    for(i=0;i<nr_class;i++)
      for(int j=i+1;j<nr_class;j++)
      {
        pairwise_prob[i][j]=Math.min(Math.max(sigmoid_predict(dec_values[k],model.probA[k],model.probB[k]),min_prob),1-min_prob);
        pairwise_prob[j][i]=1-pairwise_prob[i][j];
        k++;
      }
    multiclass_probability(nr_class,pairwise_prob,prob_estimates);
    int prob_max_idx = 0;
    for(i=1;i<nr_class;i++)
      if(prob_estimates[i] > prob_estimates[prob_max_idx])
        prob_max_idx = i;
    return model.label[prob_max_idx];
  }
  else 
    return svm_predict(model, x);
}

代码示例来源:origin: prestosql/presto

@Override
public Integer classify(FeatureVector features)
{
  requireNonNull(model, "model is null");
  return (int) svm.svm_predict(model, toSvmNodes(features));
}

代码示例来源:origin: prestosql/presto

@Override
public double regress(FeatureVector features)
{
  requireNonNull(model, "model is null");
  return svm.svm_predict(model, toSvmNodes(features));
}

代码示例来源:origin: chungkwong/MathOCR

public boolean isTextual(ConnectedComponent ele){
  return (int)(svm.svm_predict(model,getFeature(ele))+0.5)==1;
}
public static svm_node[] getFeature(ConnectedComponent ele){

代码示例来源:origin: net.sf.tweety/machinelearning

@Override
public Category classify(Observation obs) {
  if(this.model != null)
    return new DoubleCategory(svm.svm_predict(this.model, obs.toSvmNode()));
  throw new RuntimeException("Support Vector Machine is not initialized");
}

代码示例来源:origin: openimaj/openimaj

/**
 *    {@inheritDoc}
 *     @see org.openimaj.ml.annotation.Annotator#annotate(java.lang.Object)
 */
@Override
public List<ScoredAnnotation<ANNOTATION>> annotate( final OBJECT object )
{
  // Extract the feature and convert to a svm_node[]
  final svm_node[] nodes = SVMAnnotator.featureToNode( this.extractor.extractFeature( object ) );
  // Use the trained SVM model to predict the new buffer's annotation
  final double x = svm.svm_predict( this.model, nodes );
  // Create a singleton list to contain the classified annotation.
  return Collections.singletonList( new ScoredAnnotation<ANNOTATION>( x > 0 ?
      this.classMap.get(SVMAnnotator.POSITIVE_CLASS) : this.classMap.get(SVMAnnotator.NEGATIVE_CLASS),
      1.0f ) );
}

代码示例来源:origin: pl.edu.icm.yadda/yadda-analysis-impl

BxZoneLabel predictZoneLabel(BxZone zone) {
  svm_node[] instance = buildDatasetForClassification(zone);
  double predictedVal = svm.svm_predict(model, instance);
  return BxZoneLabel.values()[(int)predictedVal];
}

代码示例来源:origin: ClearTK/cleartk

public OUTCOME_TYPE classify(List<Feature> features) throws CleartkProcessingException {
 FeatureVector featureVector = this.featuresEncoder.encodeAll(features);
 ENCODED_OUTCOME_TYPE encodedOutcome = decodePrediction(libsvm.svm.svm_predict(
   this.model,
   convertToLIBSVM(featureVector)));
 return outcomeEncoder.decode(encodedOutcome);
}

代码示例来源:origin: org.cleartk/cleartk-ml-libsvm

public OUTCOME_TYPE classify(List<Feature> features) throws CleartkProcessingException {
 FeatureVector featureVector = this.featuresEncoder.encodeAll(features);
 ENCODED_OUTCOME_TYPE encodedOutcome = decodePrediction(libsvm.svm.svm_predict(
   this.model,
   convertToLIBSVM(featureVector)));
 return outcomeEncoder.decode(encodedOutcome);
}

代码示例来源:origin: pl.edu.icm.yadda/yadda-analysis-impl

@Override
public BxDocument classifyZones(BxDocument document) throws AnalysisException 
{       
  for (BxZone zone: document.asZones()) {
    svm_node[] instance = buildDatasetForClassification(zone);
    double predictedVal = svm.svm_predict(model, instance);
    System.out.println("predictedVal " + predictedVal + " " + BxZoneLabel.values()[(int)predictedVal/100] + " (" + zone.getLabel() + ")");
    zone.setLabel(BxZoneLabel.values()[(int)predictedVal/100]);
  }
  return document;
}

代码示例来源:origin: chungkwong/MathOCR

@Override
public NavigableSet<CharacterCandidate> recognize(ConnectedComponent component,Object model,CharacterList list){
  SvmModel svmModel=(SvmModel)model;
  int variables=svmModel.getFeatures().stream().mapToInt((name)->((VectorFeature)Features.REGISTRY.get(name)).getDimension()).sum();
  svm_node[] vector=new svm_node[variables];
  int j=0;
  for(String name:svmModel.getFeatures()){
    double[] sub=(double[])Features.REGISTRY.get(name).extract(component);
    for(double d:sub){
      svm_node node=new svm_node();
      node.index=j;
      node.value=d;
      vector[j++]=node;
    }
  }
  int candidate=(int)(svm.svm_predict(svmModel.getModel(),vector)+0.5);
  if(candidate>=0&&candidate<list.getCharacters().size()){
    TreeSet<CharacterCandidate> treeSet=new TreeSet<>();
    treeSet.add(list.getCharacters().get(candidate).toCandidate(component.getBox(),1.0));
    return treeSet;
  }else{
    return Collections.emptyNavigableSet();
  }
}
@Override

代码示例来源:origin: jatecs/jatecs

public double classifyTest(IIndex testIndex, int docID) {
  ClassificationResult res = new ClassificationResult();
  IIntIterator feats = testIndex.getContentDB()
      .getDocumentFeatures(docID);
  svm_node[] doc = new svm_node[testIndex.getContentDB()
      .getDocumentFeaturesCount(docID)];
  int i = 0;
  int featID = 0;
  while (feats.hasNext()) {
    featID = feats.next();
    svm_node node = new svm_node();
    node.index = featID + 1;
    node.value = testIndex.getWeightingDB().getDocumentFeatureWeight(
        docID, featID);
    doc[i++] = node;
  }
  res.documentID = docID;
  double prediction = svm.svm_predict(_model, doc);
  return prediction;
}

相关文章