Example usage for weka.classifiers.trees.j48 Distribution Distribution

List of usage examples for weka.classifiers.trees.j48 Distribution Distribution

Introduction

In this page you can find the example usage for weka.classifiers.trees.j48 Distribution Distribution.

Prototype

public Distribution(Distribution toMerge, int index) 

Source Link

Document

Creates distribution with two bags by merging all bags apart of the indicated one.

Usage

From source file:myclassifier.myC45Pack.MyClassifierTree.java

/**
 * Builds the tree structure with hold out set
 *
 * @param train the data for which the tree structure is to be
 * generated./*w  ww  . ja v a2 s  . c  o m*/
 * @param test the test data for potential pruning
 * @param keepData is training Data to be kept?
 * @throws Exception if something goes wrong
 */
public void buildTree(Instances train, Instances test, boolean keepData) throws Exception {
    //local variable
    Instances[] localTrain, localTest;
    int i;

    if (keepData) {
        this.train = train;
    }
    isLeaf = false;
    isEmpty = false;
    childTree = null;
    localModel = toSelectModel.selectModel(train, test);
    this.test = new Distribution(test, localModel);
    if (localModel.numSubsets() > 1) {
        localTrain = localModel.split(train);
        localTest = localModel.split(test);
        train = test = null;
        childTree = new MyClassifierTree[localModel.numSubsets()];
        for (i = 0; i < childTree.length; i++) {
            childTree[i] = getNewTree(localTrain[i], localTest[i]);
            localTrain[i] = null;
            localTest[i] = null;
        }
    } else {
        //tidak ada 
        isLeaf = true;
        if (Utils.eq(train.sumOfWeights(), 0))
            isEmpty = true;
        train = test = null;
    }
}

From source file:org.knime.knip.suise.node.port.WekaClassifierPortObject.java

License:Open Source License

/**
 * {@inheritDoc}/*from w  w w  .j av a 2s.  c o m*/
 */
@Override
public JComponent[] getViews() {

    JPanel panel = new JPanel(new GridLayout(1, 2));

    // classifier info
    JPanel classifierInfoPanel = new JPanel();
    String text = m_classifier.getClass().getSimpleName() + "\n";
    text += m_classifier.toString();
    classifierInfoPanel.add(new JTextArea(text));
    classifierInfoPanel.setBorder(BorderFactory.createTitledBorder("Weka Classifier Details"));
    panel.add(new JScrollPane(classifierInfoPanel));

    // training instances info
    if (m_trainingInstances.numInstances() > 0) {
        JPanel dataInfoPanel = new JPanel();
        text = "Training instances\n\n";
        Distribution distr = new Distribution(1, m_trainingInstances.numClasses());
        for (Instance i : m_trainingInstances) {
            try {
                distr.add(0, i);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        text += "Class-distribution: " + Arrays.toString(distr.matrix()[0]) + " (labels: "
                + Arrays.toString(m_modelspec.getClassLabels()) + ")" + "\n\n";
        text += m_trainingInstances.toSummaryString();

        dataInfoPanel.add(new JTextArea(text));
        dataInfoPanel.setBorder(BorderFactory.createTitledBorder("Training Instances Details"));
        panel.add(new JScrollPane(dataInfoPanel));
    }

    panel.setName("Weka Outport");
    return new JComponent[] { panel };
}