/** * Creates an Instances object with the attributes we will be calculating. * * @return the Instances structure. */ private Instances makeHeader() { ArrayList<Attribute> fv = new ArrayList<Attribute>(); fv.add(new Attribute("Margin")); fv.add(new Attribute("Current")); fv.add(new Attribute("Cumulative")); return new Instances("MarginCurve", fv, 100); }
/** * Return the structure of the result of applying this Expression * as an Attribute. * * @return the structure of the result of applying this Expression as an * Attribute. */ protected Attribute getOutputDef() { if (m_opType == FieldMetaInfo.Optype.CONTINUOUS) { return new Attribute("Constant: " + m_continuousConst); } ArrayList<String> nom = new ArrayList<String>(); nom.add(m_categoricalConst); return new Attribute("Constant: " + m_categoricalConst, nom); }
Operator() { ArrayList<Attribute> a = new ArrayList<Attribute>(); for (int i=0; i<attrs.length-1; i++) { a.add(new Attribute(attrs[i])); // numeric } ArrayList<String> d = new ArrayList<String>(); d.add("false"); d.add("true"); a.add(new Attribute(attrs[attrs.length-1], d)); // nominal attribute data = new Instances("Buh", a, 0); data.setClassIndex(attrs.length-1); // the CLASS } }
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - * only the structure is required). * @return true if the outputFormat may be collected immediately * @throws Exception if the format couldn't be set successfully */ @Override public boolean setInputFormat(Instances instanceInfo) throws Exception { Instances outputFormat; Attribute newAttribute; super.setInputFormat(instanceInfo); m_Counter = -1; m_Index.setUpper(instanceInfo.numAttributes()); outputFormat = new Instances(instanceInfo, 0); newAttribute = new Attribute(m_Name); if ((m_Index.getIndex() < 0) || (m_Index.getIndex() > getInputFormat().numAttributes())) { throw new IllegalArgumentException("Index out of range"); } outputFormat.insertAttributeAt(newAttribute, m_Index.getIndex()); setOutputFormat(outputFormat); return true; }
/** * Converts training data to numeric version. The class variable is replaced * by a pseudo-class used by LogitBoost. * * @param data the data to convert * @return the converted data * @throws Exception if something goes wrong */ protected Instances getNumericData(Instances data) throws Exception { if (m_numericDataHeader == null) { m_numericDataHeader = new Instances(data, 0); int classIndex = m_numericDataHeader.classIndex(); m_numericDataHeader.setClassIndex(-1); m_numericDataHeader.replaceAttributeAt(new Attribute("'pseudo class'"), classIndex); m_numericDataHeader.setClassIndex(classIndex); } Instances numericData = new Instances(m_numericDataHeader, data.numInstances()); for (Instance inst : data) { numericData.add(new UnsafeInstance(inst)); } return numericData; }
/** * InsertZintoD - Insert data Z[][] to Instances D (e.g., as labels). * NOTE: Assumes binary labels! * @see #addZtoD(Instances, double[][], int) */ private static Instances insertZintoD(Instances D, double Z[][]) { int L = Z[0].length; // add attributes for(int j = 0; j < L; j++) { D.insertAttributeAt(new Attribute("c"+j,Arrays.asList(new String[]{"0","1"})),j); } // add values Z[0]...Z[N] to D // (note that if D.numInstances() < Z.length, only some are added) for(int j = 0; j < L; j++) { for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(j,Z[i][j] > 0.5 ? 1.0 : 0.0); } } D.setClassIndex(L); return D; }
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(); }
File subdir = new File(directoryPath + File.separator + subdir2); if (subdir.isDirectory()) { classes.add(subdir2); atts.add(new Attribute("text", (ArrayList<String>) null)); if (m_OutputFilename) { atts.add(new Attribute("filename", (ArrayList<String>) null)); atts.add(new Attribute("@@class@@", classes)); m_structure = new Instances(relName, atts, 0); m_structure.setClassIndex(m_structure.numAttributes() - 1);
/** * Return the structure of the result of applying this Expression * as an Attribute. * * @return the structure of the result of applying this Expression as an * Attribute. */ protected Attribute getOutputDef() { if (m_opType == FieldMetaInfo.Optype.CONTINUOUS) { return new Attribute("Constant: " + m_continuousConst); } ArrayList<String> nom = new ArrayList<String>(); nom.add(m_categoricalConst); return new Attribute("Constant: " + m_categoricalConst, nom); }
/** * generates the header * * @return the header */ private Instances makeHeader() { ArrayList<Attribute> fv = new ArrayList<Attribute>(); fv.add(new Attribute(PROB_COST_FUNC_NAME)); fv.add(new Attribute(NORM_EXPECTED_COST_NAME)); fv.add(new Attribute(THRESHOLD_NAME)); return new Instances(RELATION_NAME, fv, 100); }
/** * Converts training data to numeric version. The class variable is replaced * by a pseudo-class used by LogitBoost. * * @param data the data to convert * @return the converted data * @throws Exception if something goes wrong */ protected Instances getNumericData(Instances data) throws Exception { if (m_numericDataHeader == null) { m_numericDataHeader = new Instances(data, 0); int classIndex = m_numericDataHeader.classIndex(); m_numericDataHeader.setClassIndex(-1); m_numericDataHeader.replaceAttributeAt(new Attribute("'pseudo class'"), classIndex); m_numericDataHeader.setClassIndex(classIndex); } Instances numericData = new Instances(m_numericDataHeader, data.numInstances()); for (Instance inst : data) { numericData.add(new UnsafeInstance(inst)); } return numericData; }
/** * InsertZintoD - Insert data Z[][] to Instances D (e.g., as labels). * NOTE: Assumes binary labels! * @see #addZtoD(Instances, double[][], int) */ private static Instances insertZintoD(Instances D, double Z[][]) { int L = Z[0].length; // add attributes for(int j = 0; j < L; j++) { D.insertAttributeAt(new Attribute("c"+j,Arrays.asList(new String[]{"0","1"})),j); } // add values Z[0]...Z[N] to D // (note that if D.numInstances() < Z.length, only some are added) for(int j = 0; j < L; j++) { for(int i = 0; i < D.numInstances(); i++) { D.instance(i).setValue(j,Z[i][j] > 0.5 ? 1.0 : 0.0); } } D.setClassIndex(L); return D; }
File subdir = new File(directoryPath + File.separator + subdir2); if (subdir.isDirectory()) { classes.add(subdir2); atts.add(new Attribute("text", (ArrayList<String>) null)); if (m_OutputFilename) { atts.add(new Attribute("filename", (ArrayList<String>) null)); atts.add(new Attribute("@@class@@", classes)); m_structure = new Instances(relName, atts, 0); m_structure.setClassIndex(m_structure.numAttributes() - 1);
@Override public Attribute makeAttribute() { ArrayList<String> vals = new ArrayList<String>(); for (Map.Entry<String, NominalStats.Count> e : m_counts.entrySet()) { vals.add(e.getKey() + "_" + e.getValue().m_count); } vals.add(MISSING_LABEL + "_" + m_numMissing); Attribute a = new Attribute(CSVToARFFHeaderMapTask.ARFF_SUMMARY_ATTRIBUTE_PREFIX + m_attributeName, vals); return a; } }
/** * Creates an Instances object with the attributes we will be calculating. * * @return the Instances structure. */ private Instances makeHeader() { ArrayList<Attribute> fv = new ArrayList<Attribute>(); fv.add(new Attribute("Margin")); fv.add(new Attribute("Current")); fv.add(new Attribute("Cumulative")); return new Instances("MarginCurve", fv, 100); }
/** * AddZtoD - Add attribute space Z[N][H] (N rows of H columns) to Instances D, which should have N rows also. * @param D dataset (of N instances) * @param Z attribute space (of N rows, H columns) * @param L column to add Z from in D */ private static Instances addZtoD(Instances D, double Z[][], int L) { int H = Z[0].length; int N = D.numInstances(); // add attributes for(int a = 0; a < H; a++) { D.insertAttributeAt(new Attribute("A"+a),L+a); } // add values Z[0]...Z[N] to D for(int a = 0; a < H; a++) { for(int i = 0; i < N; i++) { D.instance(i).setValue(L+a,Z[i][a]); } } D.setClassIndex(L); return D; }
for (int i = 0; i < m_types.length; i++) { if (m_types[i] == TYPE.STRING || m_types[i] == TYPE.UNDETERMINED) { attribs.add(new Attribute(m_structure.attribute(i).name(), (java.util.List<String>) null)); } else if (m_types[i] == TYPE.NUMERIC) { attribs.add(new Attribute(m_structure.attribute(i).name())); } else if (m_types[i] == TYPE.NOMINAL) { LinkedHashSet<String> vals = m_nominalVals.get(i); theVals.add(v); theVals.add("*unknown*"); attribs.add(new Attribute(m_structure.attribute(i).name(), theVals)); } else { attribs .add(new Attribute(m_structure.attribute(i).name(), m_dateFormat)); m_structure = new Instances(m_structure.relationName(), attribs, 0);
public QuestionWord() { ArrayList<String> attributeValues = new ArrayList<String>(); attributeValues.add("Who"); attributeValues.add("What"); attributeValues.add("When"); attributeValues.add("Where"); attributeValues.add("Which"); attributeValues.add(Commands); attributeValues.add(AuxVerb); attributeValues.add("How"); attributeValues.add("Misc"); attribute = new Attribute("QuestionWord", attributeValues); }
/** * generates the header * * @return the header */ private Instances makeHeader() { ArrayList<Attribute> fv = new ArrayList<Attribute>(); fv.add(new Attribute(PROB_COST_FUNC_NAME)); fv.add(new Attribute(NORM_EXPECTED_COST_NAME)); fv.add(new Attribute(THRESHOLD_NAME)); return new Instances(RELATION_NAME, fv, 100); }
for (int i = 0; i < m_types.length; i++) { if (m_types[i] == TYPE.STRING || m_types[i] == TYPE.UNDETERMINED) { attribs.add(new Attribute(m_structure.attribute(i).name(), (java.util.List<String>) null)); } else if (m_types[i] == TYPE.NUMERIC) { attribs.add(new Attribute(m_structure.attribute(i).name())); } else if (m_types[i] == TYPE.NOMINAL) { LinkedHashSet<String> vals = m_nominalVals.get(i); theVals.add(v); theVals.add("*unknown*"); attribs.add(new Attribute(m_structure.attribute(i).name(), theVals)); } else { attribs .add(new Attribute(m_structure.attribute(i).name(), m_dateFormat)); m_structure = new Instances(m_structure.relationName(), attribs, 0);