FastVector destValues = new FastVector(); destValues.addElement("dummy"); destValues.addElement("tree"); destValues.addElement("flower"); Attribute destClassAttribute = new Attribute("destClass", destValues);
/** * Initialize the classes structure */ protected void initClassesList() { this.classesList = new FastVector(); this.classesList.addElement("?"); //this.classesList.addElement("fake_class"); }
FastVector attributes = new FastVector(); attributes.addElement(new Attribute("attr", (FastVector) null));
FastVector classAttr = new FastVector(); classAttr .addElement(new Attribute("class", (FastVector) null));
/** * 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; }
Attribute dateTimeAttribute = new Attribute("dateTime","yyyy-MM-dd HH:mm"); Attribute valueAttribute = new Attribute("value"); FastVector fvWekaAttributesLinear = new FastVector(2); fvWekaAttributesLinear.addElement(dateTimeAttribute); fvWekaAttributesLinear.addElement(valueAttribute); Instances isTrainingSet = new Instances("Relation", fvWekaAttributesLinear, 100000); double[] attValues = new double[isTrainingSet.numAttributes()]; attValues[0] = isTrainingSet.attribute("dateTime").parseDate("2009-07-15 10:00"); attValues[1] = 0.5;
protected void updateConfidence(double[] confidences, boolean[] truth) { for (int labelIndex = 0; labelIndex < numOfLabels; labelIndex++) { int classValue; boolean actual = truth[labelIndex]; if (actual) { classValue = 1; } else { classValue = 0; } double[] dist = new double[2]; dist[1] = confidences[labelIndex]; dist[0] = 1 - dist[1]; m_Predictions[labelIndex].addElement(new NominalPrediction(classValue, dist, 1)); all_Predictions.addElement(new NominalPrediction(classValue, dist, 1)); } } }
protected static FastVector createFastVector(Map<Integer,String> features, Set<String> authors){ FastVector fv = new FastVector(features.size()+1); for (Integer i : features.keySet()){ fv.addElement(new Attribute(features.get(i),i)); } //author names FastVector authorNames = new FastVector(); List<String> authorsSorted = new ArrayList<String>(authors.size()); authorsSorted.addAll(authors); for (String author : authorsSorted){ authorNames.addElement(author); } Attribute authorNameAttribute = new Attribute("authorName", authorNames); fv.addElement(authorNameAttribute); return fv; }
FastVector atts = new FastVector(); // assuming all your eight attributes are numeric for( int i = 1; i <= 8; i++ ) { atts.addElement(new Attribute("att" + i)); // - numeric } Instances data = new Instances("MyRelation", atts, 0); data.add(dataInst);
/** * Gets the attributes for all internal EDAs (n internal EDAs -> n attributes). * The attributes are named after the internal EDAs and an additional index * to prevent ambiguities if more than one EDABasic of the same type is used. * @return a FastVector with the attributes */ private FastVector getAttributes(){ FastVector attrs = new FastVector(); for (int i = 0; i < this.edas.size(); i++){ EDABasic<? extends TEDecision> eda = this.edas.get(i); attrs.addElement(new Attribute(eda.getClass().getSimpleName()+i)); } return attrs; }
double[][] data = { {4058.0, 4059.0, ... }, /* first instance */ {19.0, 20.0, ... } /* second instance */ }; int numAtts = data[0].length; FastVector atts = new FastVector(numAtts); for (int att = 0; att < numAtts; att++) { atts.addElement(new Attribute("Attribute" + att, att)); } int numInstances = data.length; Instances dataset = new Instances("Dataset", atts, numInstances); for (int inst = 0; inst < numInstances; inst++) { dataset.add(new Instance(1.0, data[inst])); } BufferedWriter writer = new BufferedWriter(new FileWriter("test.arff")); writer.write(dataset.toString()); writer.flush(); writer.close();
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); FastVector values = new FastVector(4); values.addElement("00"); values.addElement("10"); values.addElement("01"); values.addElement("11"); classAttribute = new Attribute("TheCLass",values); int L = D.classIndex(); h = new Classifier[L][L]; for(int j = 0; j < L; j++) { for(int k = j+1; k < L; k++) { if (getDebug()) System.out.print("."); Instances D_pair = convert(D,j,k); h[j][k] = (AbstractClassifier)AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); h[j][k].buildClassifier(D_pair); } if (getDebug()) System.out.println(""); } }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); FastVector values = new FastVector(4); values.addElement("00"); values.addElement("10"); values.addElement("01"); values.addElement("11"); classAttribute = new Attribute("TheCLass",values); int L = D.classIndex(); h = new Classifier[L][L]; for(int j = 0; j < L; j++) { for(int k = j+1; k < L; k++) { if (getDebug()) System.out.print("."); Instances D_pair = convert(D,j,k); h[j][k] = (AbstractClassifier)AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); h[j][k].buildClassifier(D_pair); } if (getDebug()) System.out.println(""); } }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); FastVector values = new FastVector(4); values.addElement("00"); values.addElement("10"); values.addElement("01"); values.addElement("11"); classAttribute = new Attribute("TheCLass",values); int L = D.classIndex(); h = new Classifier[L][L]; for(int j = 0; j < L; j++) { for(int k = j+1; k < L; k++) { if (getDebug()) System.out.print("."); Instances D_pair = convert(D,j,k); h[j][k] = (AbstractClassifier)AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions()); h[j][k].buildClassifier(D_pair); } if (getDebug()) System.out.println(""); } }
public ObviousWekaInstances(Table table, String name, FastVector attInfo, int cap) { super(name, attInfo, cap); this.table = table; IntIterator iter = this.table.rowIterator(); while(iter.hasNext()) { m_Instances.addElement(new ObviousWekaInstance( new TupleImpl(table, iter.nextInt()), this)); } for (int i = 0; i < table.getSchema().getColumnCount(); i++) { m_Attributes.addElement(attribute(i)); } }
protected Instances createInstances() { FastVector attributes = new FastVector(); for (int i = 0; i < schema.getColumnCount(); i++) { Attribute attribute = createAttribute(schema.getColumnName(i), schema.getColumnType(i)); attributes.addElement(attribute); } return new Instances("test", attributes, 1); }
/** * Creates attributes vector from an obvious table. * @return vector from attributes */ protected FastVector createAttributes() { FastVector attributes = new FastVector(); for (int i = 0; i < table.getSchema().getColumnCount(); i++) { attributes.addElement(createAttribute(table.getSchema().getColumnName(i), table.getSchema().getColumnType(i))); } return attributes; }
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(); }
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(); }
@Override public void add(Instance instance) { double[] values = instance.toDoubleArray(); Object[] obvValues = new Object[table.getSchema().getColumnCount()]; for (int i = 0; i < table.getSchema().getColumnCount(); i++) { Attribute att = instance.attribute(i); Class<?> c = table.getSchema().getColumnType(i); if(att.isString() && ObviousWekaUtils.isString(c)) { obvValues[i] = instance.attribute(i).value(i); } else if (att.isNumeric() && ObviousWekaUtils.isNumeric(c)) { obvValues[i] = instance.value(att); } else if (att.isDate() && ObviousWekaUtils.isDate(c)) { obvValues[i] = new Date((long) values[i]); } else { obvValues[i] = null; } } Tuple tuple = new TupleImpl(table.getSchema(), obvValues); m_Instances.addElement(new ObviousWekaInstance(tuple, this)); table.addRow(tuple); }