Package weka.core

Examples of weka.core.Instances


  }

  private Instances removeIgnoreCols(Instances inst, int[] toIgnore) {

    Remove af = new Remove();
    Instances retI = null;

    try {
      af.setAttributeIndicesArray(toIgnore);
      af.setInvertSelection(false);
      af.setInputFormat(inst);
View Full Code Here


    }

    VisualizePanel temp_vp = null;
    String temp_grph = null;
    Clusterer temp_clusterer = null;
    Instances temp_trainHeader = null;
    int[] temp_ignoreAtts = null;
   
    if (o != null) {
      for (int i = 0; i < o.size(); i++) {
  Object temp = o.elementAt(i);
  if (temp instanceof Clusterer) {
    temp_clusterer = (Clusterer)temp;
  } else if (temp instanceof Instances) { // training header
    temp_trainHeader = (Instances)temp;
  } else if (temp instanceof int[]) { // ignored attributes
    temp_ignoreAtts = (int[])temp;
  } else if (temp instanceof VisualizePanel) { // normal errors
    temp_vp = (VisualizePanel)temp;
  } else if (temp instanceof String) { // graphable output
    temp_grph = (String)temp;
  }
      }
    }
     
    final VisualizePanel vp = temp_vp;
    final String grph = temp_grph;
    final Clusterer clusterer = temp_clusterer;
    final Instances trainHeader = temp_trainHeader;
    final int[] ignoreAtts = temp_ignoreAtts;
   
    JMenuItem saveModel = new JMenuItem("Save model");
    if (clusterer != null) {
      saveModel.addActionListener(new ActionListener() {
View Full Code Here

    int returnVal = m_FileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File selected = m_FileChooser.getSelectedFile();
      Clusterer clusterer = null;
      Instances trainHeader = null;
      int[] ignoredAtts = null;

      m_Log.statusMessage("Loading model from file...");

      try {
  InputStream is = new FileInputStream(selected);
  if (selected.getName().endsWith(".gz")) {
    is = new GZIPInputStream(is);
  }
  ObjectInputStream objectInputStream = new ObjectInputStream(is);
  clusterer = (Clusterer) objectInputStream.readObject();
  try { // see if we can load the header & ignored attribute info
    trainHeader = (Instances) objectInputStream.readObject();
    ignoredAtts = (int[]) objectInputStream.readObject();
  } catch (Exception e) {} // don't fuss if we can't
  objectInputStream.close();
      } catch (Exception e) {
 
  JOptionPane.showMessageDialog(null, e, "Load Failed",
              JOptionPane.ERROR_MESSAGE);
     

      m_Log.statusMessage("OK");
     
      if (clusterer != null) {
  m_Log.logMessage("Loaded model from file '" + selected.getName()+ "'");
  String name = (new SimpleDateFormat("HH:mm:ss - ")).format(new Date());
  String cname = clusterer.getClass().getName();
  if (cname.startsWith("weka.clusterers."))
    cname = cname.substring("weka.clusterers.".length());
  name += cname + " from file '" + selected.getName() + "'";
  StringBuffer outBuff = new StringBuffer();

  outBuff.append("=== Model information ===\n\n");
  outBuff.append("Filename:     " + selected.getName() + "\n");
  outBuff.append("Scheme:       " + clusterer.getClass().getName());
  if (clusterer instanceof OptionHandler) {
    String [] o = ((OptionHandler) clusterer).getOptions();
    outBuff.append(" " + Utils.joinOptions(o));
  }
  outBuff.append("\n");

  if (trainHeader != null) {

    outBuff.append("Relation:     " + trainHeader.relationName() + '\n');
    outBuff.append("Attributes:   " + trainHeader.numAttributes() + '\n');
    if (trainHeader.numAttributes() < 100) {
      boolean [] selectedAtts = new boolean [trainHeader.numAttributes()];
      for (int i = 0; i < trainHeader.numAttributes(); i++) {
        selectedAtts[i] = true;
      }
     
      if (ignoredAtts != null)
        for (int i=0; i<ignoredAtts.length; i++)
    selectedAtts[ignoredAtts[i]] = false;
    
      for (int i = 0; i < trainHeader.numAttributes(); i++) {
        if (selectedAtts[i]) {
    outBuff.append("              " + trainHeader.attribute(i).name()
             + '\n');
        }
      }
      if (ignoredAtts != null) {
        outBuff.append("Ignored:\n");
        for (int i=0; i<ignoredAtts.length; i++)
    outBuff.append("              "
             + trainHeader.attribute(ignoredAtts[i]).name()
             + '\n');
      }
    } else {
      outBuff.append("              [list of attributes omitted]\n");
    }
View Full Code Here

          public void run() {
            // Copy the current state of things
            m_Log.statusMessage("Setting up...");

            StringBuffer outBuff = m_History.getNamedBuffer(name);
            Instances userTest = null;

            ClustererAssignmentsPlotInstances plotInstances = ExplorerDefaults.getClustererAssignmentsPlotInstances();
            plotInstances.setClusterer(clusterer);
            if (m_TestInstances != null) {
              userTest = new Instances(m_TestInstances);
            }
   
            boolean saveVis = m_StorePredictionsBut.isSelected();
            String grph = null;

            try {
              if (userTest == null) {
                throw new Exception("No user test set has been opened");
              }
              if (trainHeader != null && !trainHeader.equalHeaders(userTest)) {
                throw new Exception("Train and test set are not compatible\n" + trainHeader.equalHeadersMsg(userTest));
              }

              m_Log.statusMessage("Evaluating on test data...");
              m_Log.logMessage("Re-evaluating clusterer (" + name + ") on test set");

              m_Log.logMessage("Started reevaluate model");
              if (m_Log instanceof TaskLogger) {
                ((TaskLogger)m_Log).taskStarted();
              }
              ClusterEvaluation eval = new ClusterEvaluation();
              eval.setClusterer(clusterer);
   
              Instances userTestT = new Instances(userTest);
              if (ignoredAtts != null) {
                userTestT = removeIgnoreCols(userTestT, ignoredAtts);
              }

              eval.evaluateClusterer(userTestT);
View Full Code Here

   * updates the capabilities filter of the GOE
   *
   * @param filter  the new filter to use
   */
  protected void updateCapabilitiesFilter(Capabilities filter) {
    Instances     tempInst;
    Capabilities   filterClass;

    if (filter == null) {
      m_ClustererEditor.setCapabilitiesFilter(new Capabilities(null));
      return;
    }
   
    if (!ExplorerDefaults.getInitGenericObjectEditorFilter())
      tempInst = new Instances(m_Instances, 0);
    else
      tempInst = new Instances(m_Instances);
    tempInst.setClassIndex(-1);
   
    if (!m_ignoreKeyList.isSelectionEmpty()) {
      tempInst = removeIgnoreCols(tempInst);
    }

View Full Code Here

      jf.setVisible(true);
      if (args.length == 1) {
  System.err.println("Loading instances from " + args[0]);
  java.io.Reader r = new java.io.BufferedReader(
         new java.io.FileReader(args[0]));
  Instances i = new Instances(r);
  sp.setInstances(i);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println(ex.getMessage());
View Full Code Here

      throw new UnsupportedAttributeTypeException("Can only handle numeric " +
              "or nominal attributes.");
    }
    m_Values.setUpper(instanceInfo.attribute(m_AttIndex.getIndex()).numValues() - 1);
    if (isNominal() && m_ModifyHeader) {
      instanceInfo = new Instances(instanceInfo, 0); // copy before modifying
      Attribute oldAtt = instanceInfo.attribute(m_AttIndex.getIndex());
      int [] selection = m_Values.getSelection();
      FastVector newVals = new FastVector();
      for (int i = 0; i < selection.length; i++) {
  newVals.addElement(oldAtt.value(selection[i]));
View Full Code Here

   * @throws Exception      in case the determination goes wrong
   */
  protected Instances determineOutputFormat(Instances inputFormat)
      throws Exception {
   
    return new Instances(inputFormat, 0);
  }
View Full Code Here

  if (instanceGeneration) {
          m_state = INCREMENTAL_LOADING;
    //    boolean start = true;
    Instance nextInstance = null;
    // load and pass on the structure first
    Instances structure = null;
    try {
            m_Loader.reset();
            //      System.err.println("NOTIFYING STRUCTURE AVAIL");
      structure = m_Loader.getStructure();
      notifyStructureAvailable(structure);
View Full Code Here

  System.err.println("Usage: AttributeSummarizer <dataset>");
  System.exit(1);
      }
      java.io.Reader r = new java.io.BufferedReader(
       new java.io.FileReader(args[0]));
      Instances inst = new Instances(r);
      final javax.swing.JFrame jf = new javax.swing.JFrame();
      jf.getContentPane().setLayout(new java.awt.BorderLayout());
      final AttributeSummarizer as = new AttributeSummarizer();
      as.setInstances(inst);
     
View Full Code Here

TOP

Related Classes of weka.core.Instances

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.