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

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

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

Instances.resampleWithWeights介绍

[英]Creates a new dataset of the same size as this dataset using random sampling with replacement according to the current instance weights. The weights of the instances in the new dataset are set to one. See also resampleWithWeights(Random, double[], boolean[]).
[中]根据当前实例权重,使用带替换的随机采样创建与此数据集大小相同的新数据集。新数据集中实例的权重设置为1。另请参见重采样WithWeights(随机、双精度[]、布尔值[])。

代码示例

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. The weights of the
 * instances in the new dataset are set to one. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random) {
 return resampleWithWeights(random, false);
}

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

@Override
public Instances resampleWithWeights(Random arg0, double[] arg1) {
 return super.resampleWithWeights(arg0, arg1);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. The weights of the
 * instances in the new dataset are set to one. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random) {
 return resampleWithWeights(random, false);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. The weights of the
 * instances in the new dataset are set to one. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param sampled an array indicating what has been sampled
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random, boolean[] sampled) {
 return resampleWithWeights(random, sampled, false);
}

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

@Override
public Instances resampleWithWeights(Random arg0) {
 return super.resampleWithWeights(arg0);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param representUsingWeights if true, copies are represented using weights
 *          in resampled data
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random,
 boolean representUsingWeights) {
 return resampleWithWeights(random, null, representUsingWeights);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param representUsingWeights if true, copies are represented using weights
 *          in resampled data
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random,
 boolean representUsingWeights) {
 return resampleWithWeights(random, null, representUsingWeights);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. The weights of the
 * instances in the new dataset are set to one. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param sampled an array indicating what has been sampled
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random, boolean[] sampled) {
 return resampleWithWeights(random, sampled, false);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param sampled an array indicating what has been sampled
 * @param representUsingWeights if true, copies are represented using weights
 *          in resampled data
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random, boolean[] sampled,
 boolean representUsingWeights) {
 return resampleWithWeights(random, sampled, representUsingWeights, 100.0);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the given weight vector. The weights of the
 * instances in the new dataset are set to one. The length of the weight
 * vector has to be the same as the number of instances in the dataset, and
 * all weights have to be positive. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param weights the weight vector
 * @return the new dataset
 * @throws IllegalArgumentException if the weights array is of the wrong
 *           length or contains negative weights.
 */
public Instances resampleWithWeights(Random random, double[] weights) {
 return resampleWithWeights(random, weights, null);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the current instance weights. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param sampled an array indicating what has been sampled
 * @param representUsingWeights if true, copies are represented using weights
 *          in resampled data
 * @return the new dataset
 */
public Instances resampleWithWeights(Random random, boolean[] sampled,
 boolean representUsingWeights) {
 return resampleWithWeights(random, sampled, representUsingWeights, 100.0);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the given weight vector. The weights of the
 * instances in the new dataset are set to one. The length of the weight
 * vector has to be the same as the number of instances in the dataset, and
 * all weights have to be positive. See also
 * resampleWithWeights(Random, double[], boolean[]).
 * 
 * @param random a random number generator
 * @param weights the weight vector
 * @return the new dataset
 * @throws IllegalArgumentException if the weights array is of the wrong
 *           length or contains negative weights.
 */
public Instances resampleWithWeights(Random random, double[] weights) {
 return resampleWithWeights(random, weights, null);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the given weight vector. The length of the weight
 * vector has to be the same as the number of instances in the dataset, and
 * all weights have to be positive. Uses Walker's method, see pp. 232 of
 * "Stochastic Simulation" by B.D. Ripley (1987).
 *
 * @param random a random number generator
 * @param weights the weight vector
 * @param sampled an array indicating what has been sampled, can be null
 * @param representUsingWeights if true, copies are represented using weights
 *          in resampled data
 * @return the new dataset
 * @throws IllegalArgumentException if the weights array is of the wrong
 *           length or contains negative weights.
 */
public Instances resampleWithWeights(Random random, double[] weights,
                   boolean[] sampled, boolean representUsingWeights) {
 return resampleWithWeights(random, weights, sampled, representUsingWeights, 100.0);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the given weight vector. The weights of the
 * instances in the new dataset are set to one. The length of the weight
 * vector has to be the same as the number of instances in the dataset, and
 * all weights have to be positive. Uses Walker's method, see pp. 232 of
 * "Stochastic Simulation" by B.D. Ripley (1987).
 * 
 * @param random a random number generator
 * @param weights the weight vector
 * @param sampled an array indicating what has been sampled, can be null
 * @return the new dataset
 * @throws IllegalArgumentException if the weights array is of the wrong
 *           length or contains negative weights.
 */
public Instances resampleWithWeights(Random random, double[] weights,
 boolean[] sampled) {
 return resampleWithWeights(random, weights, sampled, false);
}

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

/**
 * Creates a new dataset of the same size as this dataset using random sampling with
 * replacement according to the given weight vector. The weights of the
 * instances in the new dataset are set to one. The length of the weight
 * vector has to be the same as the number of instances in the dataset, and
 * all weights have to be positive. Uses Walker's method, see pp. 232 of
 * "Stochastic Simulation" by B.D. Ripley (1987).
 * 
 * @param random a random number generator
 * @param weights the weight vector
 * @param sampled an array indicating what has been sampled, can be null
 * @return the new dataset
 * @throws IllegalArgumentException if the weights array is of the wrong
 *           length or contains negative weights.
 */
public Instances resampleWithWeights(Random random, double[] weights,
 boolean[] sampled) {
 return resampleWithWeights(random, weights, sampled, false);
}

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

/**
  * Resamples the dataset using {@link Instances#resampleWithWeights(Random)}
  * if there are any instance weights other than 1.0 set. Simply returns the
  * dataset if no instance weights other than 1.0 are set.
  *
  * @param insts    the dataset to resample
  * @param rand    the random number generator to use
  * @return        the (potentially) resampled dataset
  */
 public static Instances resampleWithWeightIfNecessary(Instances insts, Random rand) {
  if (hasInstanceWeights(insts))
   return insts.resampleWithWeights(rand);
  else
   return insts;
 }
}

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

/**
  * Resamples the dataset using {@link Instances#resampleWithWeights(Random)}
  * if there are any instance weights other than 1.0 set. Simply returns the
  * dataset if no instance weights other than 1.0 are set.
  *
  * @param insts    the dataset to resample
  * @param rand    the random number generator to use
  * @return        the (potentially) resampled dataset
  */
 public static Instances resampleWithWeightIfNecessary(Instances insts, Random rand) {
  if (hasInstanceWeights(insts))
   return insts.resampleWithWeights(rand);
  else
   return insts;
 }
}

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

/**
 * Returns a training set for a particular iteration.
 * 
 * @param iteration the number of the iteration for the requested training set.
 * @return the training set for the supplied iteration number
 * @throws Exception if something goes wrong when generating a training set.
 */
@Override
protected synchronized Instances getTrainingSet(int iteration) throws Exception {
 Random r = new Random(m_Seed + iteration);
 // create the in-bag indicator array if necessary
 if (m_CalcOutOfBag) {
  m_inBag[iteration] = new boolean[m_data.numInstances()];
  return m_data.resampleWithWeights(r, m_inBag[iteration], getRepresentCopiesUsingWeights(), m_BagSizePercent);
 } else {
  return m_data.resampleWithWeights(r, null, getRepresentCopiesUsingWeights(), m_BagSizePercent);
 }
}

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

/**
 * Returns a training set for a particular iteration.
 * 
 * @param iteration the number of the iteration for the requested training set.
 * @return the training set for the supplied iteration number
 * @throws Exception if something goes wrong when generating a training set.
 */
@Override
protected synchronized Instances getTrainingSet(int iteration) throws Exception {
 Random r = new Random(m_Seed + iteration);
 // create the in-bag indicator array if necessary
 if (m_CalcOutOfBag) {
  m_inBag[iteration] = new boolean[m_data.numInstances()];
  return m_data.resampleWithWeights(r, m_inBag[iteration], getRepresentCopiesUsingWeights(), m_BagSizePercent);
 } else {
  return m_data.resampleWithWeights(r, null, getRepresentCopiesUsingWeights(), m_BagSizePercent);
 }
}

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

/**
 * builds the classifier.
 *
 * @param data     the training data to be used for generating the
 *             classifier.
 * @throws Exception     if the classifier could not be built successfully
 */
public void buildClassifier(Instances data) throws Exception {
 // can classifier handle the data?
 getCapabilities().testWithFail(data);
 boolean resample = getForceResampleWithWeights()
  || (!(m_Classifier instanceof WeightedInstancesHandler) && ResampleUtils.hasInstanceWeights(data));
 if (resample) {
  if (getDebug())
 System.err.println(getClass().getName() + ": resampling training data");
  data = data.resampleWithWeights(new Random(m_Seed));
 }
 m_Classifier.buildClassifier(data);
}

相关文章

Instances类方法