Java Code Examples for meka.core.Result#getMeasurement()

The following examples show how to use meka.core.Result#getMeasurement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MicroCurve.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args.length != 1)
    throw new IllegalArgumentException("Required arguments: <dataset>");

  System.out.println("Loading data: " + args[0]);
  Instances data = DataSource.read(args[0]);
  MLUtils.prepareData(data);

  System.out.println("Cross-validate BR classifier");
  BR classifier = new BR();
  // further configuration of classifier
  String top = "PCut1";
  String vop = "3";
  Result result = Evaluation.cvModel(classifier, data, 10, top, vop);

  JFrame frame = new JFrame("Micro curve");
  frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(new BorderLayout());
  Instances performance = (Instances) result.getMeasurement(CURVE_DATA_MICRO);
  try {
    VisualizePanel panel = createPanel(performance);
    frame.getContentPane().add(panel, BorderLayout.CENTER);
  }
  catch (Exception ex) {
    System.err.println("Failed to create plot!");
    ex.printStackTrace();
  }
  frame.setSize(800, 600);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
 
Example 2
Source File: ShowMacroCurve.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the action lister to use in the menu.
 *
 * @param history   the current history
 * @param index     the selected history item
 * @return          the listener
 */
@Override
public ActionListener getActionListener(final ResultHistoryList history, final int index) {
	final Result result = history.getResultAt(index);

	return new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			JDialog dialog = new JDialog((Frame) null, history.getSuffixAt(index), false);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.getContentPane().setLayout(new BorderLayout());
			Instances performance = (Instances) result.getMeasurement(CURVE_DATA_MACRO);
			try {
				VisualizePanel panel = createPanel(performance);
				dialog.getContentPane().add(panel, BorderLayout.CENTER);
			}
			catch (Exception ex) {
				System.err.println("Failed to create plot!");
				ex.printStackTrace();
			}
			dialog.setSize(800, 600);
			dialog.setLocationRelativeTo(null);
			dialog.setVisible(true);
		}
	};
}
 
Example 3
Source File: IncrementalPerformance.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the action lister to use in the menu.
 *
 * @param history   the current history
 * @param index     the selected history item
 * @return          the listener
 */
@Override
public ActionListener getActionListener(final ResultHistoryList history, final int index) {
	final Result result = history.getResultAt(index);

	return new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			JDialog dialog = new JDialog((Frame) null, history.getSuffixAt(index), false);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.getContentPane().setLayout(new BorderLayout());
			Instances performance = (Instances) result.getMeasurement(RESULTS_SAMPLED_OVER_TIME);
			try {
				VisualizePanel panel = createPanel(performance);
				dialog.getContentPane().add(panel, BorderLayout.CENTER);
			}
			catch (Exception ex) {
				System.err.println("Failed to create plot!");
				ex.printStackTrace();
			}
			dialog.setSize(800, 600);
			dialog.setLocationRelativeTo(null);
			dialog.setVisible(true);
		}
	};
}
 
Example 4
Source File: ShowMicroCurve.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the action lister to use in the menu.
 *
 * @param history   the current history
 * @param index     the selected history item
 * @return          the listener
 */
@Override
public ActionListener getActionListener(final ResultHistoryList history, final int index) {
	final Result result = history.getResultAt(index);

	return new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			JDialog dialog = new JDialog((Frame) null, history.getSuffixAt(index), false);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.getContentPane().setLayout(new BorderLayout());
			Instances performance = (Instances) result.getMeasurement(CURVE_DATA_MICRO);
			try {
				VisualizePanel panel = createPanel(performance);
				dialog.getContentPane().add(panel, BorderLayout.CENTER);
			}
			catch (Exception ex) {
				System.err.println("Failed to create plot!");
				ex.printStackTrace();
			}
			dialog.setSize(800, 600);
			dialog.setLocationRelativeTo(null);
			dialog.setVisible(true);
		}
	};
}
 
Example 5
Source File: DeepMethodsTests.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
public void testDeepML() {
	System.out.println("Test Stacked Boltzmann Machines with an off-the-shelf multi-label classifier");
	DeepML dbn = new DeepML();

	MCC h = new MCC();
	SMO smo = new SMO();
	smo.setBuildCalibrationModels(true);
	h.setClassifier(smo);

	dbn.setClassifier(h);
	dbn.setE(100);
	dbn.setH(30);

	Result r = EvaluationTests.cvEvaluateClassifier(dbn);
	System.out.println("DeepML + MCC" + r.getMeasurement("Accuracy"));
	String s = (String)r.getMeasurement("Accuracy");
	assertTrue("DeepML+MCC Accuracy Correct", s.startsWith("0.53")); // Good enough 
}
 
Example 6
Source File: DeepMethodsTests.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
public void testDBPNN() {
	
	System.out.println("Test Back Prop Neural Network with pre-trained weights (via RBM)");
	DBPNN dbn = new DBPNN();
	dbn.setClassifier(new BPNN());
	dbn.setDebug(true);

	try {
		dbn.setOptions(Utils.splitOptions("-H 30 -E 500 -r 0.1 -m 0.2"));
	} catch(Exception e) {
		System.err.println("Fatal Error");
		e.printStackTrace();
		System.exit(1);
	}
	Result r = EvaluationTests.cvEvaluateClassifier(dbn);
	String s = (String)r.getMeasurement("Accuracy");
	System.out.println("DBPNN + _" + r.getMeasurement("Accuracy"));
	assertTrue("DBPNN Accuracy Correct", s.equals("0.556 +/- 0.038"));
}
 
Example 7
Source File: ROC.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args.length != 1)
    throw new IllegalArgumentException("Required arguments: <dataset>");

  System.out.println("Loading data: " + args[0]);
  Instances data = DataSource.read(args[0]);
  MLUtils.prepareData(data);

  System.out.println("Cross-validate BR classifier");
  BR classifier = new BR();
  // further configuration of classifier
  String top = "PCut1";
  String vop = "3";
  Result result = Evaluation.cvModel(classifier, data, 10, top, vop);

  JFrame frame = new JFrame("ROC");
  frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(new BorderLayout());
  JTabbedPane tabbed = new JTabbedPane();
  frame.getContentPane().add(tabbed, BorderLayout.CENTER);
  Instances[] curves = (Instances[]) result.getMeasurement(CURVE_DATA);
  for (int i = 0; i < curves.length; i++) {
    try {
      ThresholdVisualizePanel panel = createPanel(curves[i], "Label " + i);
      tabbed.addTab("" + i, panel);
    }
    catch (Exception ex) {
      System.err.println("Failed to create plot for label " + i);
      ex.printStackTrace();
    }
  }
  frame.setSize(800, 600);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
 
Example 8
Source File: MacroCurve.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args.length != 1)
    throw new IllegalArgumentException("Required arguments: <dataset>");

  System.out.println("Loading data: " + args[0]);
  Instances data = DataSource.read(args[0]);
  MLUtils.prepareData(data);

  System.out.println("Cross-validate BR classifier");
  BR classifier = new BR();
  // further configuration of classifier
  String top = "PCut1";
  String vop = "3";
  Result result = Evaluation.cvModel(classifier, data, 10, top, vop);

  JFrame frame = new JFrame("Macro curve");
  frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(new BorderLayout());
  Instances performance = (Instances) result.getMeasurement(CURVE_DATA_MACRO);
  try {
    VisualizePanel panel = createPanel(performance);
    frame.getContentPane().add(panel, BorderLayout.CENTER);
  }
  catch (Exception ex) {
    System.err.println("Failed to create plot!");
    ex.printStackTrace();
  }
  frame.setSize(800, 600);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
 
Example 9
Source File: PrecisionRecall.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args.length != 1)
    throw new IllegalArgumentException("Required arguments: <dataset>");

  System.out.println("Loading data: " + args[0]);
  Instances data = DataSource.read(args[0]);
  MLUtils.prepareData(data);

  System.out.println("Cross-validate BR classifier");
  BR classifier = new BR();
  // further configuration of classifier
  String top = "PCut1";
  String vop = "3";
  Result result = Evaluation.cvModel(classifier, data, 10, top, vop);

  JFrame frame = new JFrame("Precision-recall");
  frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(new BorderLayout());
  JTabbedPane tabbed = new JTabbedPane();
  frame.getContentPane().add(tabbed, BorderLayout.CENTER);
  Instances[] curves = (Instances[]) result.getMeasurement(CURVE_DATA);
  for (int i = 0; i < curves.length; i++) {
    try {
      ThresholdVisualizePanel panel = createPanel(curves[i], "Label " + i);
      tabbed.addTab("" + i, panel);
    }
    catch (Exception ex) {
      System.err.println("Failed to create plot for label " + i);
      ex.printStackTrace();
    }
  }
  frame.setSize(800, 600);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
 
Example 10
Source File: SaveCSV.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the action lister to use in the menu.
 *
 * @param history   the current history
 * @param index     the selected history item
 * @return          the listener
 */
@Override
public ActionListener getActionListener(final ResultHistoryList history, final int index) {
	final Result result = history.getResultAt(index);

	return new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			Instances performance = (Instances) result.getMeasurement(IncrementalPerformance.RESULTS_SAMPLED_OVER_TIME);

			int retVal = getFileChooser().showSaveDialog(null);
			if (retVal != MekaFileChooser.APPROVE_OPTION)
				return;
			File file = getFileChooser().getSelectedFile();


			try {

				CSVSaver saver = new CSVSaver();
				saver.setInstances(performance);
				saver.setFile(getFileChooser().getSelectedFile());
				saver.writeBatch();
			} catch (Exception ex) {
				String msg = "Failed to write to '" + file + "'!";
				System.err.println(msg);
				ex.printStackTrace();
				JOptionPane.showMessageDialog( null, msg + "\n" + e);
			}
		}
	};
}
 
Example 11
Source File: AbstractShowThresholdCurve.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the action lister to use in the menu.
 *
 * @param history   the current history
 * @param index     the selected history item
 * @return          the listener
 */
@Override
public ActionListener getActionListener(final ResultHistoryList history, final int index) {
	final Result result = history.getResultAt(index);

	return new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			JDialog dialog = new JDialog((Frame) null, history.getSuffixAt(index), false);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			JTabbedPane tabbed = new JTabbedPane();
			dialog.getContentPane().setLayout(new BorderLayout());
			dialog.getContentPane().add(tabbed, BorderLayout.CENTER);
			Instances[] curves = (Instances[]) result.getMeasurement(CURVE_DATA);
			for (int i = 0; i < curves.length; i++) {
				try {
					ThresholdVisualizePanel panel = createPanel(curves[i], "Label " + i);
					tabbed.addTab("" + i, panel);
				}
				catch (Exception ex) {
					System.err.println("Failed to create plot for label " + i);
					ex.printStackTrace();
				}
			}
			dialog.setSize(800, 600);
			dialog.setLocationRelativeTo(null);
			dialog.setVisible(true);
		}
	};
}
 
Example 12
Source File: LPMethodsTests.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
public void testLC() {

		Result r = null;

		// Test LC
		LC lc = new LC();
		lc.setClassifier(new SMO());
		r = EvaluationTests.cvEvaluateClassifier(lc);
		String s = (String)r.getMeasurement("Accuracy");
		System.out.println("LC "+s);
		TestHelper.assertAlmostEquals("LC Accuracy Correct", "0.568 +/- 0.032", (String)s, 1);

		// Test PS (0,0) -- should be identical
		PS ps = new PS();
		ps.setClassifier(new SMO());
		r = EvaluationTests.cvEvaluateClassifier(ps);
		System.out.println("PS "+r.getMeasurement("Accuracy"));
		assertTrue("PS(0,0) Accuracy Identical to LC", s.equals(r.getMeasurement("Accuracy")));

		// Test PS (3,1) -- should be faster 
		ps.setP(3);
		ps.setN(1);

		r = EvaluationTests.cvEvaluateClassifier(ps);
		System.out.println("PS(3,1) "+r.getMeasurement("Accuracy"));
		TestHelper.assertAlmostEquals("PS(3,1) Accuracy Correct", "0.565 +/- 0.04", (String)r.getMeasurement("Accuracy"), 1);

		// Test EPS
		EnsembleML eps = new EnsembleML();
		eps.setClassifier(ps);
		r = EvaluationTests.cvEvaluateClassifier(eps);
		System.out.println("EPS "+r.getMeasurement("Accuracy"));
		TestHelper.assertAlmostEquals("EPS Accuracy Correct", "0.574 +/- 0.042", (String)r.getMeasurement("Accuracy"), 1);
	}