Package weka.core

Examples of weka.core.Instance


    }
    //pseudoInremental: Load all instances into main memory in batch mode and give them incrementally to user
    if(m_pseudoIncremental){
        setRetrieval(INCREMENTAL);
        if(m_datasetPseudoInc.numInstances() > 0){
            Instance current = m_datasetPseudoInc.instance(0);
            m_datasetPseudoInc.delete(0);
            return current;
        }
        else{
            resetStructure();
            return null;
        }
    }
    //real incremental mode. At the moment(version 1.0) only for MySQL and HSQLDB (Postgres not tested, should work)
    setRetrieval(INCREMENTAL);
    try{
        if(!m_DataBaseConnection.isConnected())
            connectToDatabase();
        //if no key columns specified by user, try to detect automatically
        if(m_firstTime && m_orderBy.size() == 0){
            if(!checkForKey())
                throw new Exception("A unique order cannot be detected automatically.\nYou have to use SELECT * in your query to enable this feature.\nMaybe JDBC driver is not able to detect key.\nDefine primary key in your database or use -P option (command line) or enter key columns in the GUI.");
        }
        if(m_firstTime){
            m_firstTime = false;
            m_rowCount = getRowCount();
        }
        //as long as not all rows has been loaded
        if(m_counter < m_rowCount){
            if (m_DataBaseConnection.execute(limitQuery(m_query,m_counter,m_choice)) == false) {
                throw new Exception("Tuple could not be retrieved.");
            }
            m_counter++;
            ResultSet rs = m_DataBaseConnection.getResultSet();
            rs.next();
            Instance current = readInstance(rs);
            rs.close();
            return current;
        }
        else{
            m_DataBaseConnection.disconnectFromDatabase();
View Full Code Here


        if(!atf.m_inc)
            System.out.println(atf.getDataSet());
        else{
            Instances structure = atf.getStructure();
            System.out.println(structure);
            Instance temp;
            do {
            temp = atf.getNextInstance(structure);
            if (temp != null) {
                System.out.println(temp);
            }
View Full Code Here

    if (m_structure == null) {
      getStructure();
    }

    // Read all instances
    Instance inst;
    while ((inst = m_ArffReader.readInstance(m_structure)) != null)
      m_structure.add(inst);
   
    Instances readIn = new Instances(m_structure);
View Full Code Here

    if (getRetrieval() == BATCH) {
      throw new IOException("Cannot mix getting Instances in both incremental and batch modes");
    }
    setRetrieval(INCREMENTAL);

    Instance current = null;
    if (m_sourceReader != null)
      current = m_ArffReader.readInstance(m_structure);
   
    if ((m_sourceReader != null) && (current == null)) {
      try {
View Full Code Here

   * @param inst the instance to turn into a string
   * @return the generated string
   */
  protected String instanceToString(Instance inst) {
    StringBuffer  result;
    Instance     outInst;
    int      i;
    String    field;

    result = new StringBuffer();
   
    if (inst instanceof SparseInstance) {
      outInst = new DenseInstance(inst.weight(), inst.toDoubleArray());
      outInst.setDataset(inst.dataset());
    }
    else {
      outInst = inst;
    }
   
    for (i = 0; i < outInst.numAttributes(); i++) {
      if (i > 0)
  result.append(m_FieldSeparator);
     
      if (outInst.isMissing(i))
  field = m_MissingValue;
      else
  field = outInst.toString(i);
     
      // make sure that custom field separators, like ";" get quoted correctly
      // as well
      if ((field.indexOf(m_FieldSeparator) > -1) && !field.startsWith("'") && !field.endsWith("'"))
  field = "'" + field + "'";
View Full Code Here

        // evaluation object is correct with respect to the mapped classifier
        Instances mappedClassifierDataset =
          ((weka.classifiers.misc.InputMappedClassifier)classifier).
            getModelHeader(new Instances(mappedClassifierHeader, 0));
        for (int zz = 0; zz < inst.numInstances(); zz++) {
          Instance mapped = ((weka.classifiers.misc.InputMappedClassifier)classifier).
            constructMappedInstance(inst.instance(zz));
          mappedClassifierDataset.add(mapped);
        }
        eval.setPriors(mappedClassifierDataset);
        if (!onlySetPriors) {
View Full Code Here

       
        if (outputPredictionsText) {
    printPredictionsHeader(outBuff, classificationOutput, "test set");
        }

        Instance instance;
        int jj = 0;
        while (source.hasMoreElements(userTestStructure)) {
    instance = source.nextElement(userTestStructure);
    plotInstances.process(instance, classifier, eval);
    if (outputPredictionsText) {
View Full Code Here

             
              if (outputPredictionsText) {
                printPredictionsHeader(outBuff, classificationOutput, "user test set");
              }

        Instance instance;
        int jj = 0;
        while (source.hasMoreElements(userTestStructure)) {
    instance = source.nextElement(userTestStructure);
    plotInstances.process(instance, classifierToUse, eval);
    if (outputPredictionsText) {
View Full Code Here

  loader.setFile(new File(options[0]));
  // incremental
  if (loader instanceof IncrementalConverter) {
    Instances structure = loader.getStructure();
    System.out.println(structure);
    Instance temp;
    do {
      temp = loader.getNextInstance(structure);
      if (temp != null)
        System.out.println(temp);
    }
View Full Code Here

      initTokenizer();

      readHeader(1000);
      initBuffers();
     
      Instance inst;
      while ((inst = readInstance(m_Data)) != null) {
        m_Data.add(inst);
      };
     
      compactify();
View Full Code Here

TOP

Related Classes of weka.core.Instance

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.