weka.core.Instances.firstInstance()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(116)

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

Instances.firstInstance介绍

[英]Returns the first instance in the set.
[中]返回集合中的第一个实例。

代码示例

代码示例来源:origin: stackoverflow.com

Instances dataUnlabeled = new Instances("TestInstances", atts, 0);
dataUnlabeled.add(newInst);
dataUnlabeled.setClassIndex(dataUnlabeled.numAttributes() - 1);        
double classif = ibk.classifyInstance(dataUnlabeled.firstInstance());

代码示例来源:origin: com.googlecode.obvious/obviousx-weka

@Override
public Instance firstInstance() {
 return super.firstInstance();
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Resets the class values of all instances using voting. For each instance
 * the class value that satisfies the most rules is choosen as new class
 * value.
 * 
 * @param dataset the dataset to work on
 * @return the changed instances
 * @throws Exception if something goes wrong
 */
private Instances voteDataset(Instances dataset) throws Exception {
 for (int i = 0; i < dataset.numInstances(); i++) {
  Instance inst = dataset.firstInstance();
  inst = votedReclassifyExample(inst);
  dataset.add(inst);
  dataset.delete(0);
 }
 return dataset;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Resets the class values of all instances using voting. For each instance
 * the class value that satisfies the most rules is choosen as new class
 * value.
 * 
 * @param dataset the dataset to work on
 * @return the changed instances
 * @throws Exception if something goes wrong
 */
private Instances voteDataset(Instances dataset) throws Exception {
 for (int i = 0; i < dataset.numInstances(); i++) {
  Instance inst = dataset.firstInstance();
  inst = votedReclassifyExample(inst);
  dataset.add(inst);
  dataset.delete(0);
 }
 return dataset;
}

代码示例来源:origin: stackoverflow.com

System.out.println(cls.classifyInstance(testing.firstInstance()));

代码示例来源:origin: hltfbk/Excitement-Open-Platform

result = classifier.classifyInstance(instances.firstInstance());
} catch (Exception e) {
  throw new EDAException(e);
try {
  confidence = Math.max(
      classifier.distributionForInstance(instances.firstInstance())[0],
      classifier.distributionForInstance(instances.firstInstance())[1]);
} catch (Exception e) {
  throw new EDAException(e);
String label = instances.firstInstance().classAttribute().value(new Double(result).intValue()).toLowerCase();

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

@Override
public double[] distributionForInstance(Instance xy) throws Exception {
  int L = xy.classIndex();
  double z[] = dbm.prob_z(MLUtils.getxfromInstance(xy));
  Instance zy = (Instance)m_InstancesTemplate.firstInstance().copy();
  MLUtils.setValues(zy,z,L);
  zy.setDataset(m_InstancesTemplate);
  return m_Classifier.distributionForInstance(zy);
}

代码示例来源:origin: Waikato/meka

@Override
public double[] distributionForInstance(Instance xy) throws Exception {
  int L = xy.classIndex();
  double z[] = dbm.prob_z(MLUtils.getxfromInstance(xy));
  Instance zy = (Instance)m_InstancesTemplate.firstInstance().copy();
  MLUtils.setValues(zy,z,L);
  zy.setDataset(m_InstancesTemplate);
  return m_Classifier.distributionForInstance(zy);
}

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

@Override
public Instances process(Instances D) throws Exception {
  //System.out.println("PROCESS! = "+D.numInstances());
  int L = D.classIndex();
  D = new Instances(D); // D_
  // rename classes 
  for(int j = 0; j < L; j++) {
    D.renameAttribute(j,encodeClass(j));
  }
  // merge labels
  D = mergeLabels(D,indices,m_P,m_N);
  // templates
  x_template = D.firstInstance();
  setOutputFormat(D);
  //System.out.println("PROCESS! => "+D);
  return D;
}

代码示例来源:origin: Waikato/meka

@Override
public Instances process(Instances D) throws Exception {
  //System.out.println("PROCESS! = "+D.numInstances());
  int L = D.classIndex();
  D = new Instances(D); // D_
  // rename classes 
  for(int j = 0; j < L; j++) {
    D.renameAttribute(j,encodeClass(j));
  }
  // merge labels
  D = mergeLabels(D,indices,m_P,m_N);
  // templates
  x_template = D.firstInstance();
  setOutputFormat(D);
  //System.out.println("PROCESS! => "+D);
  return D;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/multiInstanceLearning

/**
 * Computes the distribution for a given exemplar
 * 
 * @param newBag the exemplar for which distribution is computed
 * @return the distribution
 * @throws Exception if the distribution can't be computed successfully
 */
@Override
public double[] distributionForInstance(Instance newBag) throws Exception {
 double[] distribution = new double[2];
 Instances test = new Instances(newBag.dataset(), 0);
 test.add(newBag);
 test = transform(test);
 test.deleteAttributeAt(0);
 Instance newInst = test.firstInstance();
 distribution = m_Classifier.distributionForInstance(newInst);
 return distribution;
}

代码示例来源:origin: olehmberg/winter

double[] distribution = this.classifier.distributionForInstance(matchInstances.firstInstance());
int positiveClassIndex = matchInstances.attribute(matchInstances.classIndex()).indexOfValue("1");
double matchConfidence = distribution[positiveClassIndex];

代码示例来源:origin: net.sf.meka.thirdparty/mulan

protected void buildInternal(MultiLabelInstances trainingData) throws Exception {
  baseLearner.build(trainingData);
  MultiLabelOutput mlo = baseLearner.makePrediction(trainingData.getDataSet().firstInstance());
  if (!mlo.hasRanking()) {
    throw new MulanRuntimeException("Learner is not a ranker");
  }
  // by default set threshold equal to the rounded average cardinality
  if (measure == null) {
    t = (int) Math.round(trainingData.getCardinality());
    t = 2;
  } else {
    // hold a reference to the trainingData in case of auto-tuning
    if (folds == 0) {
      double[] diff = computeThreshold(baseLearner, trainingData, measure);
      t = Utils.minIndex(diff);
    } else {
      autoTuneThreshold(trainingData, measure, folds);
    }
  }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

irisData.firstInstance().setMissing(0); // set one value to missing
Instances irisSummaryHeader = getIrisSummaryHeader();
 task.processInstance(irisData.firstInstance());
 fail("Should have thrown an exception as we have not yet called init()");
} catch (DistributedWekaException e) {
 task.processInstance(irisData.firstInstance());
 fail("Should have thrown an exception as we have not set any starting centroids to use yet");
} catch (DistributedWekaException e) {
initialCenters.add(irisData.firstInstance());
initialCenters.add(irisData.instance(50));
initialCenters.add(irisData.instance(100));

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Test
public void testInitializationDontReplaceMissing() throws Exception {
 Instances irisData = CorrelationMatrixMapTaskTest.getIris();
 irisData.firstInstance().setMissing(0); // set one value to missing
 Instances irisSummaryHeader = getIrisSummaryHeader();
 task.setDontReplaceMissingValues(true);
 try {
  task.processInstance(irisData.firstInstance());
  fail("Should have thrown an exception as we have not yet called init()");
 } catch (DistributedWekaException e) {
  task.processInstance(irisData.firstInstance());
  fail("Should have thrown an exception as we have not set any starting centroids to use yet");
 } catch (DistributedWekaException e) {
 initialCenters.add(irisData.firstInstance());
 initialCenters.add(irisData.instance(50));
 initialCenters.add(irisData.instance(100));

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

initialCenters.add(irisData.firstInstance());
initialCenters.add(irisData.instance(50));
initialCenters.add(irisData.instance(100));

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

initialCenters.add(irisData.firstInstance());
initialCenters.add(irisData.instance(50));
initialCenters.add(irisData.instance(100));

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

initialCenters.add(irisData.firstInstance());
initialCenters.add(irisData.instance(50));
initialCenters.add(irisData.instance(100));

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

initialCenters.add(irisData.firstInstance());
initialCenters.add(irisData.instance(50));
initialCenters.add(irisData.instance(100));

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Test
public void testClusteringMissingValuesReplacementOnly() throws Exception {
 Instances irisData = CorrelationMatrixMapTaskTest.getIris();
 Instances irisSummaryHeader = getIrisSummaryHeader();
 KMeansMapTask task = new KMeansMapTask();
 task.init(irisSummaryHeader);
 assertFalse(task.getDontReplaceMissingValues());
 Instances initialCenters = new Instances(irisData, 0);
 initialCenters.add(irisData.firstInstance());
 initialCenters.add(irisData.instance(50));
 initialCenters.add(irisData.instance(100));
 initialCenters = task.applyFilters(initialCenters);
 task.setCentroids(initialCenters);
 // processInstance() should not raise exceptions now
 for (int i = 0; i < irisData.numInstances(); i++) {
  task.processInstance(irisData.instance(i));
 }
 List<Instances> centroidStats = task.getCentroidStats();
 assertEquals(3, centroidStats.size());
 // size of each should be 50 instances
 for (Instances i : centroidStats) {
  Attribute summary = i.attribute(5);
  assertEquals(50,
   (int) ArffSummaryNumericMetric.COUNT
    .valueFromAttribute(summary));
 }
}

相关文章

Instances类方法