Example usage for weka.core Instances resampleWithWeights

List of usage examples for weka.core Instances resampleWithWeights

Introduction

In this page you can find the example usage for weka.core Instances resampleWithWeights.

Prototype

public Instances resampleWithWeights(Random random, double[] weights, boolean[] sampled) 

Source Link

Document

Creates a new dataset of the same size as this dataset using random sampling with replacement according to the given weight vector.

Usage

From source file:Bilbo.java

License:Open Source License

/**
 * Returns a training set for a particular iteration.
 * //  ww w . ja v  a2  s.c om
 * @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(Instances p_data, int iteration) throws Exception {
    int bagSize = (int) (p_data.numInstances() * (m_BagSizePercent / 100.0));
    Instances bagData = null;
    Random r = new Random(m_Seed + iteration);

    // create the in-bag dataset
    if (m_CalcOutOfBag && p_data.classIndex() != -1) {
        m_inBag[iteration] = new boolean[p_data.numInstances()];
        bagData = p_data.resampleWithWeights(r, m_inBag[iteration], getRepresentCopiesUsingWeights());
    } else {
        bagData = p_data.resampleWithWeights(r, getRepresentCopiesUsingWeights());
        if (bagSize < p_data.numInstances()) {
            bagData.randomize(r);
            Instances newBagData = new Instances(bagData, 0, bagSize);
            bagData = newBagData;
        }
    }

    return bagData;
}