/** * Returns the data set. * @param numatt an {@code int} that represents the number of attributes. * @param numclus an {@code int} that represents the number of clusters. * @return {@link Instances} object that represents the data set. */ private Instances getDataset(int numatt, int numclus) { FastVector attributes = new FastVector(); for (int i = 0; i < numatt; i++) { attributes.addElement(new Attribute("att" + (i + 1))); } if(numclus > 0){ FastVector classLabels = new FastVector(); for (int i = 0; i < numclus; i++) { classLabels.addElement("class" + (i + 1)); } attributes.addElement(new Attribute("class", classLabels)); } Instances myDataset = new Instances("horizon", attributes, 0); if(numclus > 0){ myDataset.setClassIndex(myDataset.numAttributes() - 1); } return myDataset; }
new FastVector<Prediction>(numToRetain); FastVector<Prediction> tmpV = new FastVector<Prediction>(); tmpV.addAll(m_Predictions); for (int i = m_Predictions.size() - 1; i >= 0; i--) { int index = r.nextInt(i + 1); downSampled.add(tmpV.get(index)); if (downSampled.size() == numToRetain) { break; tmpV.swap(i, index);
FastVector[] ass=ap.getAllTheRules(); for (FastVector rule : ass) { if (rule == null) continue; System.out.println("---> " + rule); for (int i = 0; i < rule.size(); ++i) { Object o = rule.elementAt(i); if (o instanceof AprioriItemSet) { System.out.println(((AprioriItemSet) o).toString(data)); } else { System.out.println("rule: "+o); } } }
/** * Initialize the classes structure */ protected void initClassesList() { this.classesList = new FastVector(); this.classesList.addElement("?"); //this.classesList.addElement("fake_class"); }
/** * Add a class in the classes set * * @param className the class * * @return true if the class has been added, false otherwise * */ protected boolean addClass(String className) { if (!this.classesList.contains(className)) { this.classesList.addElement(className); return true; } return false; }
testCapabilities(D); int L = D.classIndex(); Instances D_ = new Instances(D,0,0); D_.deleteAttributeAt(0); FastVector classes = new FastVector(L); for (int j = 0; j < L; j++) classes.addElement("C"+j); D_.insertAttributeAt(new Attribute("ClassY",classes),0); D_.setClassIndex(0);
FastVector atts = new FastVector(); for (int i = 0; i < getInputFormat().numAttributes(); i++) { if (i == documentAtt) { atts.addElement(new Attribute("Term_frequency")); // 0 atts.addElement(new Attribute("IDF")); // 1 atts.addElement(new Attribute("TFxIDF")); // 2 atts.addElement(new Attribute("First_occurrence")); // 3 atts.addElement(new Attribute("Last_occurrence")); // 4 atts.addElement(new Attribute("Spread")); // 5 atts.addElement(new Attribute("Domain_keyphraseness")); // 6 atts.addElement(new Attribute("Length")); // 7 atts.addElement(new Attribute("Generality")); // 8 atts.addElement(new Attribute("Node_degree")); // 9 atts.addElement(new Attribute("Wikipedia_keyphraseness")); // 10 atts.addElement(new Attribute("Wikipedia_inlinks")); // 11 atts.addElement(new Attribute("Wikipedia_generality")); // 12 FastVector vals = new FastVector(2); vals.addElement("False"); vals.addElement("True"); atts.addElement(new Attribute("Keyphrase?", vals)); } else { atts.addElement(new Attribute("Keyphrase?")); classifierData = new Instances("ClassifierData", atts, 0); classifierData.setClassIndex(numFeatures);
FastVector atts = new FastVector(3); atts.addElement(new Attribute("filename", (FastVector) null)); atts.addElement(new Attribute("doc", (FastVector) null)); atts.addElement(new Attribute("keyphrases", (FastVector) null)); Instances data = new Instances("keyphrase_training_data", atts, 0); newInst[0] = data.attribute(0).addStringValue("inputFile"); newInst[1] = data.attribute(1).addStringValue(text); newInst[2] = Instance.missingValue(); data.add(new Instance(1.0, newInst));
public void buildClassifier(Instances data) throws Exception { m_ReducedHeaders[m_classifierNumber] = new Instances[ m_Groups[m_classifierNumber].length ]; FastVector transformedAttributes = new FastVector( m_data.numAttributes() ); FastVector fv = new FastVector( m_Groups[m_classifierNumber][j].length + 1 ); for( int k = 0; k < m_Groups[m_classifierNumber][j].length; k++ ) { String newName = m_data.attribute( m_Groups[m_classifierNumber][j][k] ).name() + "_" + k; fv.addElement( m_data.attribute( m_Groups[m_classifierNumber][j][k] ).copy(newName) ); fv.addElement( m_data.classAttribute( ).copy() ); Instances dataSubSet = new Instances( "rotated-" + m_classifierNumber + "-" + j + "-", fv, 0); for( int a = 0; a < projectedData.numAttributes() - 1; a++ ) { String newName = projectedData.attribute(a).name() + "_" + j; transformedAttributes.addElement( projectedData.attribute(a).copy(newName)); transformedAttributes.addElement( m_data.classAttribute().copy() ); Instances transformedData = new Instances( "rotated-" + m_classifierNumber + "-", transformedAttributes, 0 );
testCapabilities(Train); int C = Train.classIndex(); FastVector ClassValues = new FastVector(C); HashSet<String> UniqueValues = new HashSet<String>(); for (int i = 0; i < Train.numInstances(); i++) { UniqueValues.add(MLUtils.toBitString(Train.instance(i),C)); ClassValues.addElement(it.next()); Attribute NewClass = new Attribute("Class", ClassValues); if(getDebug()) System.out.println("("+m_InstancesTemplate.attribute(0).numValues()+" classes, "+NewTrain.numInstances()+" ins. )"); if(getDebug()) System.out.print("Building Classifier "+m_Classifier.getClass()+" with "+ClassValues.size()+" possible classes .. "); m_Classifier.buildClassifier(NewTrain); if(getDebug()) System.out.println("Done");
/** * Makes the format for the level-1 data. * * @param instances the level-0 format * @return the format for the meta data * @throws Exception if an error occurs */ protected Instances metaFormat(Instances instances) throws Exception { FastVector attributes = new FastVector(); Instances metaFormat; for (int i = 0; i<instances.numAttributes(); i++) { if ( i != instances.classIndex() ) { attributes.addElement(instances.attribute(i)); } } FastVector nomElements = new FastVector(2); nomElements.addElement("0"); nomElements.addElement("1"); attributes.addElement(new Attribute("PredConf",nomElements)); metaFormat = new Instances("Meta format", attributes, 0); metaFormat.setClassIndex(metaFormat.numAttributes()-1); return metaFormat; }
FastVector atts = new FastVector(); for (int i = 1; i < getInputFormat().numAttributes(); i++) { if (i == documentAtt) { atts.addElement(new Attribute("Candidate_name", atts.addElement(new Attribute("Candidate_original", atts.addElement(new Attribute("Term_frequency")); // 0 atts.addElement(new Attribute("IDF")); // 1 atts.addElement(new Attribute("TFxIDF")); // 2 atts.addElement(new Attribute("First_occurrence")); // 3 atts.addElement(new Attribute("Last_occurrence")); // 4 atts.addElement(new Attribute("Spread")); // 5 atts.addElement(new Attribute("Domain_keyphraseness")); // 6 atts.addElement(new Attribute("Length")); // 7 atts.addElement(new Attribute("Generality")); // 8 atts.addElement(new Attribute("Node_degree")); // 9 atts.addElement(new Attribute("Wikipedia_keyphraseness")); // 10 atts.addElement(new Attribute("Wikipedia_inlinks")); // 11 atts.addElement(new Attribute("Wikipedia_generality")); // 12 atts.addElement(new Attribute("Probability")); // 16 atts.addElement(new Attribute("Rank")); // 17 FastVector vals = new FastVector(2); vals.addElement("False"); vals.addElement("True"); atts.addElement(new Attribute("Keyphrase?", vals)); } else {
FastVector ClassValues = new FastVector(L); for(String y : distinctCombinations.keySet()) ClassValues.addElement(y); Attribute NewClass = new Attribute("Class", ClassValues); NewTrain.insertAttributeAt(NewClass,0); NewTrain.setClassIndex(0); for (int i = 0; i < D.numInstances(); i++) { String comb = MLUtils.toBitString(D.instance(i),L); if(ClassValues.contains(comb)) //if its class value exists NewTrain.instance(i).setClassValue(comb);
Instances instances = new Instances("EOP", attrs, 1); FastVector values = new FastVector(); values.addElement("NONENTAILMENT"); values.addElement("ENTAILMENT"); instances.insertAttributeAt(new Attribute("prediction", values), instances.numAttributes()); instances.setClassIndex(edas.size()); // set class attribute -> last attribute which is prediction for (int i = 0; i < features.size(); i++){ Double score = features.get(i); instance.setValue((Attribute) attrs.elementAt(i), score); instances.add(instance); String label = instances.firstInstance().classAttribute().value((int)result);
try { List<String> lines = FileUtils.readLines(goldAnswersFile); goldAnswers = new FastVector(lines.size()); goldAnswers.addElement(line); FastVector attrs = new FastVector(); attrs.addElement(new Attribute(component.getComponentName())); attrs.addElement(new Attribute("gold", goldAnswers)); Instances instances = new Instances("EOP", attrs, 1); instances.setClassIndex(getComponents().size()); instance.setValue((Attribute) attrs.elementAt(i), score); instance.setValue((Attribute) attrs.elementAt(attrs.size() - 1), 0); // gold instances.add(instance); String label = instances.firstInstance().classAttribute().value(new Double(result).intValue()).toLowerCase();
Attribute attr6 = new Attribute("class", (FastVector) null); FastVector attributes = new FastVector(); attributes.addElement(attr1); attributes.addElement(attr2); attributes.addElement(attr3); attributes.addElement(attr4); attributes.addElement(attr5); attributes.addElement(attr6); testing.setClassIndex(testing.numAttributes() - 1); double[] values = new double[testing.numAttributes()]; values[0] = testing.attribute(0).addStringValue(type); values[1] = Integer.parseInt(bitrate);
FastVector fvWekaAttributes = new FastVector(featureSize + 1); // + 1 for label column FastVector fvBooleanVal = new FastVector(2); fvBooleanVal.addElement("true"); fvBooleanVal.addElement("false"); attr = new Attribute(Integer.toString(i) + "_aBoolean", fvBooleanVal); fvWekaAttributes.addElement(attr); break; FastVector fvNominalVal = new FastVector(elist.length); for(int j=0; j < elist.length; j++) fvNominalVal.addElement(elist[j].toString()); attr = new Attribute(Integer.toString(i) + "_aNominal", fvNominalVal); fvWekaAttributes.addElement(attr); break; attr = new Attribute(Integer.toString(i) + "_aNumeric"); fvWekaAttributes.addElement(attr); break; FastVector fvClassVal = new FastVector(2); fvClassVal.addElement(DecisionLabel.Entailment.toString()); fvClassVal.addElement(DecisionLabel.NonEntailment.toString()); Attribute ClassAttribute = new Attribute("theClass", fvClassVal); fvWekaAttributes.addElement(ClassAttribute);
private void trainModel(Map<Long, Double> metricData) throws Exception { //Model has a single metric_value attribute Attribute value = new Attribute("metric_value"); FastVector attributes = new FastVector(); attributes.addElement(value); trainingData = new Instances("metric_value_data", attributes, 0); for (Double val : metricData.values()) { double[] valArray = new double[] { val }; Instance instance = new Instance(1.0, valArray); trainingData.add(instance); } //Create and train the model model = new SimpleKMeans(); model.setNumClusters(k); model.setMaxIterations(20); model.setPreserveInstancesOrder(true); model.buildClusterer(trainingData); clusterCentroids = model.getClusterCentroids(); centroidAssignments = model.getAssignments(); setMeanDistancesToCentroids(); }
FastVector fvClassVal = new FastVector(2); fvClassVal.addElement("yes"); fvClassVal.addElement("no"); Attribute Class = new Attribute("ScheduledFirst", fvClassVal); FastVector fvWekaAttributes = new FastVector(7); fvWekaAttributes.addElement(PT1); fvWekaAttributes.addElement(w1); fvWekaAttributes.addElement(d1); fvWekaAttributes.addElement(PT2); fvWekaAttributes.addElement(w2); fvWekaAttributes.addElement(d2); fvWekaAttributes.addElement(Class); double[] attValues = new double[dataset.numAttributes()]; attValues[0] = 50; attValues[1] = 5; dataset.add(i1); dataset.setClassIndex(dataset.numAttributes()-1);