Package weka.core

Examples of weka.core.Instance


   */
  public static Instances scramble(Instances src, Instances dst, final int attIndex, int[] perm) {

    for (int i = 0; i < src.numInstances(); i++) {

      Instance scrambled = dst.instance(i);

      if (attIndex > 0)
        scrambled.setValue(attIndex - 1, src.instance(i).value(attIndex - 1));
      scrambled.setValue(attIndex, src.instance(perm[i]).value(attIndex));
    }

    return dst;
  }
View Full Code Here


       
          double lambda_d = 1.0;
          for(ClassifierInstance c : ensemble){
            double k = this.pureBoostOption.isSet() ? lambda_d : MiscUtils.poisson(lambda_d, this.classifierRandom);
            if (k > 0.0) {
                  Instance weightedInst = (Instance) inst.copy();
                  weightedInst.setWeight(inst.weight() * k);
                  c.getClassifier().trainOnInstance(weightedInst);
              }
              if (c.getClassifier().correctlyClassifies(inst)) {
                  c.setScms(c.getScms() + lambda_d);
                  lambda_d *= this.trainingWeightSeenByModel / (2 * c.getScms());
 
View Full Code Here

        filter.input(inst);
      } catch (Exception e) {
        e.printStackTrace();
      }
     
      Instance filteredValue;
      while((filteredValue = filter.output()) != null){
        collector.emit(new Values(filteredValue));
      }
    }
   
View Full Code Here

  @Override
  public void execute(Tuple input) {
    //Get the post
    Post newPost = (Post)input.getValue(0);
    //Turn it into an instance
    Instance inst = new DenseInstance(2);
    inst.setDataset(INST_HEADERS);
    inst.setValue(0, newPost.getTitle());
    inst.setValue(1, newPost.getSubReddit());
    //emit these to a new bolt that collects instances
    _collector.emit(new Values(inst));
    _collector.ack(input);
  }
View Full Code Here

        // Create an empty training set
        Instances trainingSet = initializeDataSet(maxNumFeats, trainingSamples.size());
        int numAtts = maxNumFeats + 1;
        Iterator<Entry<Integer, Double>> currentIt;
        Entry<Integer, Double> tempEntry;
        Instance iExample;
        int i = 0;
        Instance originalCopy = getNewInstance(numAtts);
        for (LinkedHashMap<Integer, Double> currentSample : trainingSamples) {
            iExample = (Instance) originalCopy.copy();
            iExample.setDataset(trainingSet);
            currentIt = currentSample.entrySet().iterator();
            while (currentIt.hasNext()) {
                tempEntry = currentIt.next();
                iExample.setValue(tempEntry.getKey(), tempEntry.getValue());
View Full Code Here

            ArffLoader loader = new ArffLoader();
            loader.setFile(new File(PropertiesGetter.getProperty("TrainingDataSetObject")));
            Instances structure = loader.getStructure();
            structure.setClassIndex(structure.numAttributes() - 1);
            int numAtts = structure.numAttributes();
            Instance instanceToClassify = getNewInstance(numAtts);
            Iterator<Entry<Integer, Double>> currentIt = sample.entrySet().iterator();
            Entry<Integer, Double> tempEntry;
            while (currentIt.hasNext()) {
                tempEntry = currentIt.next();
                instanceToClassify.setValue(tempEntry.getKey(), tempEntry.getValue());
            }
            instanceToClassify.setDataset(structure);
            instanceToClassify.setClassMissing();
            try {
                return cModel.classifyInstance(instanceToClassify);
            } catch (Exception ex) {
                Logger.getLogger(WekaWrapper.class.getName()).log(Level.SEVERE, null, ex);
                System.out.println(ex.toString());
View Full Code Here

            }
        }
    }

    private Instance getNewInstance(int numAttributes) {
        Instance newInst = new Instance(numAttributes);
        for (int j = 0; j < numAttributes; j++) {
            newInst.setValue(j, 0.0);
        }
        return newInst;
    }
View Full Code Here

    classAttribut = dataSet.attribute(dataSet.classIndex());
  }
 
  public Instance getInstance(OWLOntology ontology, Query query){
    List<String> featureList = getFeatures(ontology, query);
    Instance instance = new Instance(featureList.size() + 1);
    instance.setDataset(dataSet);
    for(int i = 0; i < featureList.size(); i ++){
      Attribute attr = instance.attribute(i);
      if(attr.isNumeric()){
        instance.setValue(i, Double.valueOf(featureList.get(i)));
      }else{
        instance.setValue(i, featureList.get(i));
      }
    }
    return instance;
  }
View Full Code Here

    }
    return translator.getResult(index);
  }
 
  public String predict(OWLOntology ontology, Query query){
    Instance instance = translator.getInstance(ontology, query);
    return predict(instance);
  }
View Full Code Here

   
    System.out.println("Test started!");
    System.out.println("Onotolgy: " + ontology);
   
    for(Query query: getQuery(ontology)){
      Instance instance = translator.getInstance(ontology, query);
     
      System.out.println("********************************");
      System.out.println("Query: " + query.getTask());
     
      testWithReasoner(ontology, query);
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.