⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perturbation_bootstrap.java

📁 Description: FASBIR(Filtered Attribute Subspace based Bagging with Injected Randomness) is a variant
💻 JAVA
字号:
package fasbir.ensemblers;

import weka.classifiers.*;
import weka.core.*;
import java.util.Random;

/**
 * <p>Description: Bootstrap sampling perturbation method</p>
 * A perturbation method which samples the training dataset. This method is more familiar as Bagging.
 * @author Y. Yu (yuy@lamda.nju.edu.cn), LAMDA Group (http://lamda.nju.edu.cn/)
 * @version 1.0
 */
public class Perturbation_Bootstrap extends PerturbationEncapsulation{
    /**
     * Generates a classifier given perturbed training dataset.
     *
     * @param data set of instances serving as training data
     * @throws Exception if the classifier has not been generated successfully
     * @todo Implement this weka.classifiers.Classifier method
     */
    public void buildClassifier(Instances dataset) throws Exception {
        Random rnd = new Random(m_Seed);
        Instances perturbedDataset = sampleDataset(rnd, dataset);
        m_Classifier.buildClassifier( perturbedDataset );
    }

    /**
     * sample data with replacement
     * @param rnd Random
     * @param data Instances data set
     * @return Instances sampled data set
     */
    protected Instances sampleDataset(Random rnd, Instances data) {
        int num_newdata = data.numInstances();
        int num_data = data.numInstances();
        Instances newdata = new Instances(data, num_newdata);
        for (int i = 0; i < num_newdata; i++) {
            Instance newins = new Instance(data.instance(rnd.nextInt(num_data)));
            newdata.add(newins);
        }
        return newdata;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -