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

📄 classifierpanel.java

📁 :<<数据挖掘--实用机器学习技术及java实现>>一书的配套源程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* *    This program is free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    This program is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the Free Software *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* *    ClassifierPanel.java *    Copyright (C) 1999 Len Trigg * */package weka.gui.explorer;import java.io.*;import java.util.LinkedList;import java.net.*;import weka.core.Instances;import weka.core.Instance;import weka.core.FastVector;import weka.core.OptionHandler;import weka.core.Attribute;import weka.core.Utils;import weka.core.Drawable;import weka.core.SerializedObject;import weka.classifiers.Classifier;import weka.classifiers.DistributionClassifier;import weka.classifiers.Evaluation;import weka.classifiers.CostMatrix;import weka.classifiers.evaluation.NominalPrediction;import weka.classifiers.evaluation.MarginCurve;import weka.classifiers.evaluation.ThresholdCurve;import weka.classifiers.evaluation.CostCurve;import weka.filters.Filter;import weka.gui.Logger;import weka.gui.TaskLogger;import weka.gui.SysErrLog;import weka.gui.GenericObjectEditor;import weka.gui.PropertyPanel;import weka.gui.ResultHistoryPanel;import weka.gui.SetInstancesPanel;import weka.gui.CostMatrixEditor;import weka.gui.PropertyDialog;import weka.gui.InstancesSummaryPanel;import weka.gui.SaveBuffer;import weka.gui.visualize.VisualizePanel;import weka.gui.visualize.PlotData2D;import weka.gui.visualize.Plot2D;import weka.gui.treevisualizer.*;import java.util.Random;import java.util.Date;import java.text.SimpleDateFormat;import java.awt.FlowLayout;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Insets;import java.awt.Font;import java.awt.Point;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.InputEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.Window;import java.awt.Dimension;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeSupport;import java.io.File;import java.io.FileWriter;import java.io.Writer;import java.io.BufferedWriter;import java.io.PrintWriter;import javax.swing.JFileChooser;import javax.swing.JPanel;import javax.swing.JLabel;import javax.swing.JButton;import javax.swing.BorderFactory;import javax.swing.JTextArea;import javax.swing.JScrollPane;import javax.swing.ScrollPaneConstants;import javax.swing.JRadioButton;import javax.swing.ButtonGroup;import javax.swing.JOptionPane;import javax.swing.JComboBox;import javax.swing.DefaultComboBoxModel;import javax.swing.JTextField;import javax.swing.SwingConstants;import javax.swing.JFrame;import javax.swing.event.ChangeListener;import javax.swing.event.ChangeEvent;import javax.swing.JViewport;import javax.swing.JCheckBox;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.JPopupMenu;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.OverlayLayout;/** * This panel allows the user to select and configure a classifier, set the * attribute of the current dataset to be used as the class, and evaluate * the classifier using a number of testing modes (test on the training data, * train/test on a percentage split, n-fold cross-validation, test on a * separate split). The results of classification runs are stored in a result * history so that previous results are accessible. * * @author Len Trigg (trigg@cs.waikato.ac.nz) * @author Mark Hall (mhall@cs.waikato.ac.nz) * @author Dave Musicant (dmusican@mathcs.carleton.edu) * @author Sebastian Celis (celiss@mathcs.carleton.edu) * @version $Revision: 1.45 $ */public class ClassifierPanel extends JPanel {  /**   * This is used to describe the status of each fold when they are sent   * out to other computers.   */  interface Status  {      int          NOT_DONE = 0,          DONE = 1;  }  /**   * When connecting to one of the other computers to give it data, this   * program must first identify if it is connecting through Weka's CLI or   * GUI options.   */  interface Connection  {      int          CV_CLI = 0,          CV_GUI = 1;  }  /** Lets the user configure the classifier */  protected GenericObjectEditor m_ClassifierEditor =    new GenericObjectEditor();  /** The panel showing the current classifier selection */  protected PropertyPanel m_CEPanel = new PropertyPanel(m_ClassifierEditor);  /** The output area for classification results */  protected JTextArea m_OutText = new JTextArea(20, 40);  /** The destination for log/status messages */  protected Logger m_Log = new SysErrLog();  /** The buffer saving object for saving output */  SaveBuffer m_SaveOut = new SaveBuffer(m_Log, this);  /** A panel controlling results viewing */  protected ResultHistoryPanel m_History = new ResultHistoryPanel(m_OutText);  /** Lets the user select the class column */  protected JComboBox m_ClassCombo = new JComboBox();  /** Click to set test mode to cross-validation */  protected JRadioButton m_CVBut = new JRadioButton("Cross-validation");  /** Click to set test mode to generate a % split */  protected JRadioButton m_PercentBut = new JRadioButton("Percentage split");  /** Click to set test mode to test on training data */  protected JRadioButton m_TrainBut = new JRadioButton("Use training set");  /** Click to set test mode to a user-specified test set */  protected JRadioButton m_TestSplitBut =    new JRadioButton("Supplied test set");  /** Check to save the predictions in the results list for visualizing      later on */  protected JCheckBox m_StorePredictionsBut =    new JCheckBox("Store predictions for visualization");  /** Check to output the model built from the training data */  protected JCheckBox m_OutputModelBut = new JCheckBox("Output model");  /** Check to output true/false positives, precision/recall for each class */  protected JCheckBox m_OutputPerClassBut =    new JCheckBox("Output per-class stats");  /** Check to output a confusion matrix */  protected JCheckBox m_OutputConfusionBut =    new JCheckBox("Output confusion matrix");  /** Check to output entropy statistics */  protected JCheckBox m_OutputEntropyBut =    new JCheckBox("Output entropy evaluation measures");  /** Check to evaluate w.r.t a cost matrix */  protected JCheckBox m_EvalWRTCostsBut =    new JCheckBox("Cost-sensitive evaluation");  protected JButton m_SetCostsBut = new JButton("Set...");  /** Click to set the settings for cross-validation */  protected JButton m_CVSettingsBut = new JButton("Settings...");  /** Check to have the cross-validation step run in parallel */  protected JCheckBox m_RunInParallelBut =    new JCheckBox("Run in parallel");  /** Click to edit the settings of running cross-validation in parallel */  protected JButton m_ParallelConfigBut =    new JButton("Configure parallelization...");  /** Label by where the port number is entered */  protected JLabel m_PortLab = new JLabel("Port Number", SwingConstants.RIGHT);  /** TextField where the port number is entered */  protected JTextField m_PortText = new JTextField();  /**   * Area where all the computers to connect to during parallel   * cross validation are entered   */  protected JTextArea m_AddressesArea      = new JTextArea(10, 25);  /** Label by where the cv folds are entered */  protected JLabel m_CVLab = new JLabel("Folds", SwingConstants.RIGHT);  /** The field where the cv folds are entered */  protected JTextField m_CVText = new JTextField("10");  /** Label by where the % split is entered */  protected JLabel m_PercentLab = new JLabel("%", SwingConstants.RIGHT);  /** The field where the % split is entered */  protected JTextField m_PercentText = new JTextField("66");  /** The button used to open a separate test dataset */  protected JButton m_SetTestBut = new JButton("Set...");  /** The frame used to show the test set selection panel */  protected JFrame m_SetTestFrame;  /** The frame used to show the cost matrix editing panel */  protected PropertyDialog m_SetCostsFrame;  /**   * Alters the enabled/disabled status of elements associated with each   * radio button   */  ActionListener m_RadioListener = new ActionListener() {    public void actionPerformed(ActionEvent e) {      updateRadioLinks();    }  };  /** Button for further output/visualize options */  JButton m_MoreOptions = new JButton("More options...");  /** Click to start running the classifier */  protected JButton m_StartBut = new JButton("Start");  /** Click to stop a running classifier */  protected JButton m_StopBut = new JButton("Stop");  /** Stop the class combo from taking up to much space */  private Dimension COMBO_SIZE = new Dimension(150, m_StartBut                                               .getPreferredSize().height);  /** The cost matrix editor for evaluation costs */  protected CostMatrixEditor m_CostMatrixEditor = new CostMatrixEditor();  /** The main set of instances we're playing with */  protected Instances m_Instances;  /** The user-supplied test set (if any) */  protected Instances m_TestInstances;  /** The user supplied test set after preprocess filters have been applied */  protected Instances m_TestInstancesCopy;  /** A thread that classification runs in */  protected Thread m_RunThread;  /** default x index for visualizing */  protected int m_visXIndex;  /** default y index for visualizing */  protected int m_visYIndex;  /** The current visualization object */  protected VisualizePanel m_CurrentVis = null;  /** The preprocess panel through which filters can be applied to      user supplied test data sets */  protected PreprocessPanel m_Preprocess = null;  /** The instances summary panel displayed by m_SetTestFrame */  protected InstancesSummaryPanel m_Summary = null;  /**   * This is the client that will connect to all of the other computers,   * if parallel cross-validation is taking place, hand off data, and   * expect results back.   *   * @author Dave Musicant (dmusican@mathcs.carleton.edu)   * @author Sebastian Celis (celiss@mathcs.carleton.edu)   */  private class GUIDistributedClient  {      /** The port the client will connect on */      private int port;      /**       * A list of strings containing the names of the computers to connect       * to       */      private LinkedList computers;      /** The predicted instances */      private Instances predInstances;      /** The actual data cross-validation is to be done on */      private Instances inst;      /** Tells the status of each fold and whether it is DONE or NOT_DONE */      private int status[];      /** The number of folds to run */      private int numFolds;      /** The number of folds completed */      private int foldsCompleted;      /** The index of the last fold calculated. */      private int lastIndexSent;      /** The classifier used in the cross-validation. */      private Classifier classifier;

⌨️ 快捷键说明

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