For IntelliJ IDEA,

Android Studio or Eclipse

- Common ways to obtain Instances

private void myMethod () {Instances i =

- Reader reader;new Instances(reader)
- ObjectInputStream objectInputStream;(Instances) objectInputStream.readObject()
- ConverterUtils.DataSource source;source.getDataSet()
- Smart code suggestions by Codota
}

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

/** * 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); }

/** * 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); }

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

/** * 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); }

/** * 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); } }

/** * 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); }

/** * 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; } }

/** * 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); }

/** * 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); }

/** * 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); }

/** * 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); }

/** * 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); }

/** * 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); } }

/** * 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; } }