Codota Logo
Classifier.classifyInstance
Code IndexAdd Codota to your IDE (free)

How to use
classifyInstance
method
in
weka.classifiers.Classifier

Best Java code snippets using weka.classifiers.Classifier.classifyInstance (Showing top 20 results out of 315)

  • Common ways to obtain Classifier
private void myMethod () {
Classifier c =
  • Codota Iconnew NaiveBayes()
  • Codota Iconnew Bagging()
  • Codota Iconnew GaussianProcesses()
  • Smart code suggestions by Codota
}
origin: stackoverflow.com

 //load model
String rootPath="/some/where/"; 
Classifier cls = (Classifier) weka.core.SerializationHelper.read(rootPath+"tree.model");

//predict instance class values
Instances originalTrain= //load or create Instances to predict

//which instance to predict class value
int s1=0;  

//perform your prediction
double value=cls.classifyInstance(originalTrain.instance(s1));

//get the name of the class value
String prediction=originalTrain.classAttribute().value((int)value); 

System.out.println("The predicted value of instance "+
          Integer.toString(s1)+
          ": "+prediction);
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Classifies the given test instance.
 *
 * @param instance     the instance to be classified
 * @return         the predicted most likely class for the instance or
 *                 Utils.missingValue() if no prediction is made
 * @throws Exception     if an error occurred during the prediction
 */
@Override
public double classifyInstance(Instance instance) throws Exception {
 return m_Classifier.classifyInstance(instance);
}
origin: Waikato/weka-trunk

/**
 * Classifies the given test instance.
 *
 * @param instance     the instance to be classified
 * @return         the predicted most likely class for the instance or
 *                 Utils.missingValue() if no prediction is made
 * @throws Exception     if an error occurred during the prediction
 */
@Override
public double classifyInstance(Instance instance) throws Exception {
 return m_Classifier.classifyInstance(instance);
}
origin: nz.ac.waikato.cms.weka/rotationForest

public double classifierInstance(Instance instance) throws Exception {
 return m_wrappedClassifier.classifyInstance(instance);
}

origin: nz.ac.waikato.cms.weka/weka-stable

@Override
public double classifyInstance(Instance inst) throws Exception {
 Instance converted = constructMappedInstance(inst);
 return m_Classifier.classifyInstance(converted);
}
origin: Waikato/weka-trunk

@Override
public double classifyInstance(Instance inst) throws Exception {
 Instance converted = constructMappedInstance(inst);
 return m_Classifier.classifyInstance(converted);
}
origin: net.sf.meka/meka

@Override
public double[] distributionForInstance(Instance instance) throws Exception {
  int c = instance.classIndex();
  double result[] = new double[c];
  Instance finstances[] = convertInstance(instance,c);
  for (int i = 0; i < c; i++) {
    result[i] = m_MultiClassifiers[i].classifyInstance(finstances[i]);
    //result[i] = m_MultiClassifiers[i].distributionForInstance(finstances[i])[1];
  }
  return result;
}
origin: net.sourceforge/javaml

@Override
public Object classify(Instance instance) {
  try {
    return utils.convertClass(wekaClass.classifyInstance(utils.instanceToWeka(instance)));
  } catch (Exception e) {
    throw new WekaException(e);
  }
}
origin: nz.ac.waikato.cms.weka/meka

@Override
public double[] distributionForInstance(Instance instance) throws Exception {
  int c = instance.classIndex(); 
  double result[] = new double[c];
  Instance finstances[] = convertInstance(instance,c);
  for (int i = 0; i < c; i++) {
    result[i] = m_MultiClassifiers[i].classifyInstance(finstances[i]);
    //result[i] = m_MultiClassifiers[i].distributionForInstance(finstances[i])[1];
  }
  return result;
}
origin: Waikato/meka

@Override
public double[] distributionForInstance(Instance instance) throws Exception {
  int c = instance.classIndex();
  double result[] = new double[c];
  Instance finstances[] = convertInstance(instance,c);
  for (int i = 0; i < c; i++) {
    result[i] = m_MultiClassifiers[i].classifyInstance(finstances[i]);
    //result[i] = m_MultiClassifiers[i].distributionForInstance(finstances[i])[1];
  }
  return result;
}
origin: sc.fiji/T2-NIT

public static final boolean classify(final double[] vector) throws Exception {
  // Obtain or generate a Thread-local instance
  Operator op;
  synchronized (table) { // avoid clashes within weka
    final Thread t = Thread.currentThread();
    op = table.get(t);
    if (null == op) {
      op = new Operator();
      table.put(t, op);
    }
  }
  // Future weka versions will use new DenseInstance(1, vector) instead
  final Instance ins = new DenseInstance(1, vector);
  ins.setDataset(op.data);
  // Was trained to return true or false, represented in weka as 0 or 1
  return 1 == ((int) Math.round(op.c.classifyInstance(ins)));
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Add a label to an instance using a classifier
 *
 * @param classifier the classifier to use
 * @param inst the instance to append prediction to
 * @param instOrig the original instance
 * @throws WekaException if a problem occurs
 */
protected void predictLabelClassifier(weka.classifiers.Classifier classifier,
 Instance inst, Instance instOrig) throws WekaException {
 try {
  double pred = classifier.classifyInstance(instOrig);
  inst.setValue(inst.numAttributes() - 1, pred);
 } catch (Exception ex) {
  throw new WekaException(ex);
 }
}
origin: net.sf.meka/meka

@Override
public double[] distributionForInstance(Instance x) throws Exception {
  int L = x.classIndex();
  //if there is only one class (as for e.g. in some hier. mtds) predict it
  if(L == 1) return new double[]{1.0};
  Instance x_ = PSUtils.convertInstance(x,L,m_InstancesTemplate); //convertInstance(x,L);
  x_.setDataset(m_InstancesTemplate);
  //Get a classification
  double y[] = new double[x_.numClasses()];
  y[(int)m_Classifier.classifyInstance(x_)] = 1.0;
  return PSUtils.convertDistribution(y,L,m_InstancesTemplate);
}
origin: Waikato/meka

@Override
public double[] distributionForInstance(Instance x) throws Exception {
  int L = x.classIndex();
  //if there is only one class (as for e.g. in some hier. mtds) predict it
  if(L == 1) return new double[]{1.0};
  Instance x_ = PSUtils.convertInstance(x,L,m_InstancesTemplate); //convertInstance(x,L);
  x_.setDataset(m_InstancesTemplate);
  //Get a classification
  double y[] = new double[x_.numClasses()];
  y[(int)m_Classifier.classifyInstance(x_)] = 1.0;
  return PSUtils.convertDistribution(y,L,m_InstancesTemplate);
}
origin: nz.ac.waikato.cms.weka/meka

@Override
 public double[] distributionForInstance(Instance mlInstance) throws Exception {
  int c = mlInstance.classIndex();
  //if there is only one class (as for e.g. in some hier. mtds) predict it
  if(c == 1) return new double[]{1.0};
  Instance slInstance = convertInstance(mlInstance,c);
  slInstance.setDataset(m_InstancesTemplate);
  //Get a classification
  double result[] = new double[slInstance.numClasses()];
  result[(int)m_Classifier.classifyInstance(slInstance)] = 1.0;
  return convertDistribution(result,c);
}
origin: stackoverflow.com

 public static void LoadAndTest(String filename_test, String filename_model) throws Exception {
  BufferedReader datafile_test = readDataFile(filename_test);
  Instances      data_test     = new Instances(datafile_test);
  data_test.setClassIndex(data_test.numAttributes() - 1);

  Classifier cls = (Classifier) weka.core.SerializationHelper.read(filename_model);
  int act = 0;
  for (int i = 0; i < data_test.numInstances(); i++) {
   double pred = cls.classifyInstance(data_test.instance(i));
   double real = data_test.instance(i).classValue();
   if (pred==real) {
    act = act + 1;
   }
  }  
  double pct = (double) act / (double) data_test.numInstances();
  System.out.println("Accuracy = " + pct);
}
origin: nz.ac.waikato.cms.weka/meka

private void classify(Instance test) throws Exception {
  // copy
  Instance copy = (Instance)test.copy();
  copy.setDataset(null);
  // delete attributes we don't need
  for(int i = excld.length-1; i >= 0; i--) {
    copy.deleteAttributeAt(this.excld[i]);
  }
  //set template
  copy.setDataset(this._template);
  //set class
  test.setValue(this.index,(int)(this.classifier.classifyInstance(copy))); 
  //carry on
  if (next!=null) next.classify(test);
}
origin: Waikato/meka

private void classify(Instance test) throws Exception {
  // copy
  Instance copy = (Instance)test.copy();
  copy.setDataset(null);
  // delete attributes we don't need
  for(int i = excld.length-1; i >= 0; i--) {
    copy.deleteAttributeAt(this.excld[i]);
  }
  //set template
  copy.setDataset(this._template);
  //set class
  test.setValue(this.index,(int)(this.classifier.classifyInstance(copy))); 
  //carry on
  if (next!=null) next.classify(test);
}
origin: net.sf.meka/meka

private void classify(Instance test) throws Exception {
  // copy
  Instance copy = (Instance)test.copy();
  copy.setDataset(null);
  // delete attributes we don't need
  for(int i = excld.length-1; i >= 0; i--) {
    copy.deleteAttributeAt(this.excld[i]);
  }
  //set template
  copy.setDataset(this._template);
  //set class
  test.setValue(this.index,(int)(this.classifier.classifyInstance(copy))); 
  //carry on
  if (next!=null) next.classify(test);
}
origin: kodapan/osm-common

@Override
public String classify(Instance instance) throws Exception {
 weka.core.Instance wekaInstance = new weka.core.Instance(wekaTrainingData.numAttributes());
 wekaInstance.setDataset(wekaTrainingData);
 double[] histogramPercent = instance.getHistogramPercent();
 for (int i = 0; i < histogramPercent.length; i++) {
  wekaInstance.setValue(i, histogramPercent[i]);
 }
 wekaInstance.setMissing(wekaTrainingData.attribute("class"));
 double wekaClassification = classifier.classifyInstance(wekaInstance);
 String classification = wekaTrainingData.attribute("class").value((int)wekaClassification);
 return classification;
}
weka.classifiersClassifierclassifyInstance

Javadoc

Classifies the given test instance. The instance has to belong to a dataset when it's being classified. Note that a classifier MUST implement either this or distributionForInstance().

Popular methods of Classifier

  • buildClassifier
    Generates a classifier. Must initialize all fields of the classifier that are not being set via opti
  • distributionForInstance
    Predicts the class memberships for a given instance. If an instance is unclassified, the returned ar
  • getCapabilities
    Returns the Capabilities of this classifier. Maximally permissive capabilities are allowed by defaul
  • getOptions
  • makeCopy
  • setOptions
  • forName
  • setDebug

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSupportFragmentManager (FragmentActivity)
  • getSharedPreferences (Context)
  • startActivity (Activity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Pattern (java.util.regex)
    A compiled representation of a regular expression. A regular expression, specified as a string, must
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JTable (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now