List of usage examples for weka.gui.treevisualizer PlaceNode2 PlaceNode2
PlaceNode2
From source file:adams.flow.sink.WekaTreeVisualizer.java
License:Open Source License
/** * Creates a tree visualizer from the token. * /* w w w. j av a 2s.c om*/ * @param token the input * @return the tree visualizer or null in case of an error */ protected TreeVisualizer createTreeVisualizer(Token token) { TreeVisualizer result; Reader reader; TreeBuild builder; Node top; NodePlace arrange; Object input; result = null; try { input = token.getPayload(); if (input instanceof WekaModelContainer) input = ((WekaModelContainer) input).getValue(WekaModelContainer.VALUE_MODEL); if (input instanceof String) { reader = new StringReader((String) input); } else if (input instanceof File) { reader = new BufferedReader(new FileReader(((File) input).getAbsolutePath())); } else { if (((Drawable) input).graphType() != Drawable.TREE) throw new IllegalArgumentException( token.getPayload().getClass().getName() + " does not generate a tree!"); reader = new StringReader(((Drawable) input).graph()); } } catch (Exception e) { handleException("Failed to instantiate reader for input!", e); return result; } builder = new TreeBuild(); top = null; arrange = new PlaceNode2(); try { top = builder.create(reader); result = new TreeVisualizer(null, top, arrange); } catch (Exception e) { handleException("Failed to parse dot notation!", e); } finally { if (reader != null) { try { reader.close(); } catch (Exception e) { // ignored } } } return result; }
From source file:adams.gui.menu.TreeVisualizer.java
License:Open Source License
/** * Launches the functionality of the menu item. *//*from w w w.j a v a2s .co m*/ @Override public void launch() { String filename; int retVal; TreeBuild builder; Node top; NodePlace arrange; ChildFrame frame; FileReader reader; if (m_Parameters.length == 0) { // choose file retVal = m_FileChooser.showOpenDialog(null); if (retVal != JFileChooser.APPROVE_OPTION) return; filename = m_FileChooser.getSelectedFile().getAbsolutePath(); } else { filename = new PlaceholderFile(m_Parameters[0]).getAbsolutePath(); } // build tree builder = new TreeBuild(); top = null; arrange = new PlaceNode2(); reader = null; try { reader = new FileReader(filename); top = builder.create(reader); } catch (Exception e) { GUIHelper.showErrorMessage(getOwner(), "Error loading file '" + filename + "':\n" + Utils.throwableToString(e)); return; } finally { if (reader != null) { try { reader.close(); } catch (Exception e) { // ignored } } } // create frame frame = createChildFrame(new weka.gui.treevisualizer.TreeVisualizer(null, top, arrange), GUIHelper.getDefaultDialogDimension()); frame.setTitle(frame.getTitle() + " - " + filename); }
From source file:adams.gui.tools.previewbrowser.TreeVisualizer.java
License:Open Source License
/** * Creates the actual preview./*from w ww. jav a 2 s .c o m*/ * * @param obj the object to create the preview for * @return the preview, null if failed to generate preview */ @Override protected PreviewPanel createPreview(Object obj) { weka.gui.treevisualizer.TreeVisualizer panel; String dot; try { dot = ((Drawable) obj).graph(); } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to obtain DOT notation:", e); dot = null; } if (dot == null) return null; panel = new weka.gui.treevisualizer.TreeVisualizer(null, dot, new PlaceNode2()); return new PreviewPanel(panel); }
From source file:Controller.CtlDataMining.java
public String arbolJ48(Instances data) { try {//from w w w. ja va 2s .c o m // Creamos un clasidicador J48 J48 j48 = new J48(); //creamos el clasificador del J48 con los datos j48.buildClassifier(data); //Creamos un objeto para la validacion del modelo con redBayesiana Evaluation evalJ48 = new Evaluation(data); /*Aplicamos el clasificador J48 hacemos validacion cruzada, de redBayesiana, con 10 campos, y el aleatorio arrancando desde 1 para la semilla*/ evalJ48.crossValidateModel(j48, data, 10, new Random(1)); //Obtenemos resultados String resJ48 = "<br><b><center>Resultados Arbol de decision J48" + "</center><br>========<br>Modelo generado indica los " + "siguientes resultados:<br>========<br></b>"; resJ48 = resJ48 + ("<b>1. Numero de instancias clasificadas:</b> " + (int) evalJ48.numInstances() + "<br>"); resJ48 = resJ48 + ("<b>2. Porcentaje de instancias correctamente " + "clasificadas:</b> " + formato.format(evalJ48.pctCorrect()) + "<br>"); resJ48 = resJ48 + ("<b>3. Numero de instancias correctamente " + "clasificadas:</b>" + (int) evalJ48.correct() + "<br>"); resJ48 = resJ48 + ("<b>4. Porcentaje de instancias incorrectamente " + "clasificadas:</b> " + formato.format(evalJ48.pctIncorrect()) + "<br>"); resJ48 = resJ48 + ("<b>5. Numero de instancias incorrectamente " + "clasificadas:</b> " + (int) evalJ48.incorrect() + "<br>"); resJ48 = resJ48 + ("<b>6. Media del error absoluto:</b> " + formato.format(evalJ48.meanAbsoluteError()) + "<br>"); resJ48 = resJ48 + ("<b>7. " + evalJ48.toMatrixString("Matriz de" + " confusion</b>").replace("\n", "<br>")); // SE GRAFICA EL ARBOL GENERADO //Se crea un Jframe Temporal final javax.swing.JFrame jf = new javax.swing.JFrame("Arbol de decision: J48"); /*Se asigna un tamao*/ jf.setSize(500, 400); /*Se define un borde*/ jf.getContentPane().setLayout(new BorderLayout()); /*Se instancia la grafica del arbol, estableciendo el tipo J48 Parametros (Listener, Tipo de arbol, Tipo de nodos) El placeNode2 colocar los nodos para que caigan en forma uniforme por debajo de su padre*/ TreeVisualizer tv = new TreeVisualizer(null, j48.graph(), new PlaceNode2()); /*Aade el arbol centrandolo*/ jf.getContentPane().add(tv, BorderLayout.CENTER); /*Aadimos un listener para la X del close*/ jf.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { jf.dispose(); } }); /*Lo visualizamos*/ jf.setVisible(true); /*Ajustamos el arbol al ancho del JFRM*/ tv.fitToScreen(); return resJ48; } catch (Exception e) { return "El error es" + e.getMessage(); } }
From source file:coreferenceresolver.gui.WekaTreeGUI.java
/** * Creates new form WekaTreeGUI/*from w w w .ja v a 2 s.c om*/ */ public WekaTreeGUI(J48 tree) throws Exception { initComponents(); this.tree = tree; // display classifier this.setTitle("Weka Classifier Tree Visualizer: J48"); this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.getContentPane().setLayout(new BorderLayout()); TreeVisualizer tv = new TreeVisualizer(null, tree.graph(), new PlaceNode2()); this.getContentPane().add(tv, BorderLayout.CENTER); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { WekaTreeGUI.this.dispose(); } }); tv.fitToScreen(); }
From source file:de.fub.maps.project.detector.model.inference.impl.ShowGraphAction.java
License:Open Source License
private JComponent createTreeGraph(String graphDescriptor) { TreeBuild builder = new TreeBuild(); NodePlace placeNode = new PlaceNode2(); Node node = builder.create(new StringReader(graphDescriptor)); return new TreeVisualizer(null, node, placeNode); }
From source file:meka.gui.explorer.classify.ShowGraphs.java
License:Open Source License
/** * Returns the action lister to use in the menu. * * @param history the current history//from ww w. j a v a2s. c o m * @param index the selected history item * @return the listener */ @Override public ActionListener getActionListener(final ResultHistoryList history, final int index) { final MultiLabelDrawable d = (MultiLabelDrawable) getClassifier(history, index); return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Map<Integer, String> graphs; Map<Integer, Integer> types; java.util.List<Integer> keys; try { types = d.graphType(); graphs = d.graph(); keys = new ArrayList<Integer>(types.keySet()); } catch (Exception ex) { System.err.println("Failed to obtain graph(s):"); ex.printStackTrace(); return; } 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); for (Integer label : keys) { int type = types.get(label); JComponent comp = null; switch (type) { case MultiLabelDrawable.TREE: TreeBuild b = new TreeBuild(); PlaceNode2 arrange = new PlaceNode2(); Node top = b.create(new StringReader(graphs.get(label))); comp = new TreeVisualizer(null, top, arrange); break; case MultiLabelDrawable.BayesNet: GraphVisualizer g = new GraphVisualizer(); g.readDOT(new StringReader(graphs.get(label))); comp = g; break; default: System.err.println("Unsupported graph type for label " + label + ": " + type); } if (comp != null) tabbed.addTab("" + label, comp); } dialog.setSize(800, 600); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } }; }
From source file:org.conqat.engine.commons.machine_learning.BaseWekaClassifier.java
License:Apache License
/** * Visualizes a decision tree in a new pop-up window. This works only if the * underlying classifier is a J48 tree./*from w ww.j a va 2 s. co m*/ */ public void debugVisualizeDecisionTree() throws ConQATException { CCSMAssert.isTrue(wekaClassifier instanceof J48, "Only J48 trees can be visualized!"); TreeVisualizer treeVisualizer; try { treeVisualizer = new TreeVisualizer(null, ((J48) wekaClassifier).graph(), new PlaceNode2()); } catch (Exception e) { throw new ConQATException(e); } JFrame frame = new JFrame("Weka Classifier Tree Visualizer: J48"); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setSize(800, 1200); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(treeVisualizer, BorderLayout.CENTER); frame.setVisible(true); treeVisualizer.fitToScreen(); }
From source file:org.processmining.analysis.clusteranalysis.ClusterJ48Analyzer.java
License:Open Source License
/** * Creates a decision tree visualization for the current classification * problem./*from ww w .j a v a 2s. c om*/ * * @return the panel to be displayed as analysis result for the current * decision point */ protected JPanel createResultVisualization() { JPanel resultViewPanel = new JPanel(new BorderLayout()); try { resultViewPanel = new J48ResultPanel(); ((J48ResultPanel) resultViewPanel) .setTreeVisualizer(new TreeVisualizer(null, ((J48) myClassifier).graph(), new PlaceNode2())); return resultViewPanel; } catch (Exception ex) { ex.printStackTrace(); return createMessagePanel("Error while creating the decision tree visualization"); } }
From source file:rdfsystem.MainFrame.java
private void classifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_classifyButtonActionPerformed try {// w w w.j a v a2s . co m String tree = DataMining.classify(manager); TreeVisualizer tv = new TreeVisualizer(null, tree, new PlaceNode2()); JDialog jf = new JDialog(); jf.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); jf.setSize(800, 600); jf.setModal(true); jf.setLocationRelativeTo(null); jf.setResizable(false); jf.getContentPane().setLayout(new BorderLayout()); jf.getContentPane().add(tv, BorderLayout.CENTER); tv.fitToScreen(); jf.setVisible(true); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); ex.printStackTrace(); } }