Example usage for weka.classifiers Evaluation toMatrixString

List of usage examples for weka.classifiers Evaluation toMatrixString

Introduction

In this page you can find the example usage for weka.classifiers Evaluation toMatrixString.

Prototype

public String toMatrixString() throws Exception 

Source Link

Document

Calls toMatrixString() with a default title.

Usage

From source file:tucil2ai.Tucil2AI.java

/**
 *
 * @param E/*from   w w  w.j  a  va 2  s  .c  om*/
 * @throws Exception
 */
public static void printEval(Evaluation E) throws Exception {
    System.out.println(E.toSummaryString("\nResults\n======\n", false));
    System.out.println(E.toClassDetailsString());
    System.out.println(E.toMatrixString());
}

From source file:view.centerPanels.ClassificationPnlCenterPredict.java

private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed

    //imate vec objekat instances i objekat naiveBayes u ovoj klasi
    //treba da izvucete ono sto je uetu u text fieldove preko liste i da napravite
    //objekat Instance (nema "s"). kad naravite objekat Instance samo ga dodate
    //na instances.add(  )..
    //onda koristite takav Instances i naiveBayes za evaluaciju i u textArea
    //ispisujete kojoj klasi pripada.. Sad ne trba matrica konfuzije potrebno
    //je da ispisete string kojoj klasi pripada
    //pogledajte klasu ClusterinPnlCenterPredict tu je odradjeno 90% onog sto se i ovde trazi
    //        instances.delete();
    for (int i = 0; i < textFields.size(); i++) {
        String text = textFields.get(i).getText().trim();

        //prekace prazna pollja jer za klasterizaciju znaci da se ona ignorisu
        //to za klasifikaciju nije slucaj
        if (!text.equals("")) {

            if (instances.attribute(i).isNominal()) {
                boolean correct = false;
                for (int j = 0; j < instances.attribute(i).numValues(); j++) {
                    if (text.equals(instances.attribute(i).value(j))) {
                        correct = true;/*from w w w .j  ava2 s  . c  o  m*/
                    }
                }
                if (!correct) {
                    JOptionPane.showMessageDialog(this,
                            "Incorrect format for attribute " + instances.attribute(i).name());
                    break;
                }
            }

            if (instances.attribute(i).isNumeric()) {
                try {
                    double value = Double.parseDouble(text);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(this,
                            "Incorrect format for attribute " + instances.attribute(i).name());
                    break;
                }
            }

        }
    }

    int numAttributes = instances.numAttributes();

    Instance instance = new Instance(numAttributes);

    for (int i = 0; i < textFields.size(); i++) {
        String text = textFields.get(i).getText().trim();

        try {
            double value = Double.parseDouble(text);
            instance.setValue(i, value);

        } catch (Exception e) {
            instance.setValue(i, text);
        }
    }

    String value = instances.attribute(numAttributes - 1).value(0);
    Attribute Att = instances.attribute(numAttributes - 1);

    instance.setValue(Att, value);
    //        instances.delete();
    //        instance.setValue((numAttributes - 1), instances.attribute(numAttributes - 1).value(0) );

    instances.add(instance);

    double[][] matrix = null;

    System.out.println(instances);
    System.out.println(naiveBayes);

    try {

        //                instances.setClassIndex(instances.numAttributes() - 1);
        Evaluation eval = new Evaluation(instances);

        eval.evaluateModel(naiveBayes, instances);

        textArea.setText(eval.toMatrixString());
        matrix = eval.confusionMatrix();

    } catch (Exception ex) {
        System.out.println("Greska: " + ex);
    }

    double[] array = new double[matrix.length];

    for (int i = 0; i < array.length; i++) {

        double sum = 0;
        for (int j = 0; j < array.length; j++) {

            sum = sum + matrix[j][i];

        }
        array[i] = sum;

    }

    String className = null;
    for (int i = 0; i < array.length; i++) {
        if (array[i] == 1) {
            className = instances.attribute(numAttributes - 1).value(i);
        }
    }

    textArea.setText("This instance belongs to class: \n\n== " + className + " ==");

    instances.delete();
}

From source file:view.centerPanels.ClassificationPnlCenterTrainNew.java

public ClassificationPnlCenterTrainNew() {
    initComponents();/*from   w w  w  .  ja v a 2  s.  co m*/

    Instances data = Data.getInstance().getInstances();

    try {
        nb = new NaiveBayes();

        data.setClassIndex(data.numAttributes() - 1);

        Evaluation eval = new Evaluation(data);

        nb.buildClassifier(data);

        eval.evaluateModel(nb, data);

        jTextArea1.setText(eval.toMatrixString());

        //                System.out.println(eval.toMatrixString());
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, ex);
    }

    setSize(MainGUI.getInstance().getPnlCenter().getWidth(), MainGUI.getInstance().getPnlCenter().getHeight());
    setVisible(true);

}