public int getNode(String sNodeName) { int iNode = 0; while (iNode < m_root.m_bayesNet.m_Instances.numAttributes()) { if (m_root.m_bayesNet.m_Instances.attribute(iNode).name() .equals(sNodeName)) { return iNode; } iNode++; } // throw new Exception("Could not find node [[" + sNodeName + "]]"); return -1; }
private static ArrayList<String> getLabels(Instances data) { int numLabels = data.classIndex(); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < numLabels; i++) { list.add(data.attribute(i).name()); } return list; } }
/** * Returns the contents of an item set as a string. * * @param instances contains the relevant header information * @return string describing the item set */ public String toString(Instances instances) { StringBuffer text = new StringBuffer(); for (int i = 0; i < instances.numAttributes(); i++) { if (m_items[i] != -1) { text.append(instances.attribute(i).name() + '='); text.append(instances.attribute(i).value(m_items[i]) + ' '); } } text.append(m_counter); return text.toString(); }
/** * change the name of a value of a node * * @param nTargetNode index of the node to set name for * @param sValue current name of the value * @param sNewValue new name of the value */ public void renameNodeValue(int nTargetNode, String sValue, String sNewValue) { // update undo stack if (m_bNeedsUndoAction) { addUndoAction(new RenameValueAction(nTargetNode, sValue, sNewValue)); } Attribute att = m_Instances.attribute(nTargetNode); int nCardinality = att.numValues(); ArrayList<String> values = new ArrayList<String>(nCardinality); for (int iValue = 0; iValue < nCardinality; iValue++) { if (att.value(iValue).equals(sValue)) { values.add(sNewValue); } else { values.add(att.value(iValue)); } } replaceAtt(nTargetNode, att.name(), values); } // renameNodeValue
public static final String toDebugString(Instances D) { int L = D.classIndex(); StringBuilder sb = new StringBuilder(); sb.append("D="+D.numInstances()); sb.append(" L="+L+" {"); for(int j = 0; j < L; j++) { sb.append(D.attribute(j).name()+" "); } sb.append("}"); return sb.toString(); }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int L = D.classIndex(); if(getDebug()) System.out.print("Creating "+L+" models ("+m_Classifier.getClass().getName()+"): "); m_MultiClassifiers = AbstractClassifier.makeCopies(m_Classifier,L); m_Templates = new Instances[L]; for(int j = 0; j < L; j++) { //Select only class attribute 'j' m_Templates[j] = MLUtils.keepAttributesAt(new Instances(D),new int[]{j},L); m_Templates[j].setClassIndex(0); //Build the classifier for that class m_MultiClassifiers[j].buildClassifier(m_Templates[j]); if(getDebug()) System.out.print(" " + (m_Templates[j].classAttribute().name())); m_Templates[j] = new Instances(m_Templates[j], 0); } }
/** * Returns the contents of an item set as a string. * * @param instances contains the relevant header information * @return string describing the item set */ public String toString(Instances instances) { StringBuffer text = new StringBuffer(); for (int i = 0; i < instances.numAttributes(); i++) { if (m_items[i] != -1) { text.append(instances.attribute(i).name() + '='); text.append(instances.attribute(i).value(m_items[i]) + ' '); } } text.append(m_counter); return text.toString(); }
private static ArrayList<String> getLabels(Instances data) { int numLabels = data.classIndex(); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < numLabels; i++) { list.add(data.attribute(i).name()); } return list; }
public int getNode(String sNodeName) { int iNode = 0; while (iNode < m_root.m_bayesNet.m_Instances.numAttributes()) { if (m_root.m_bayesNet.m_Instances.attribute(iNode).name() .equals(sNodeName)) { return iNode; } iNode++; } // throw new Exception("Could not find node [[" + sNodeName + "]]"); return -1; }
public static final String toDebugString(Instances D) { int L = D.classIndex(); StringBuilder sb = new StringBuilder(); sb.append("D="+D.numInstances()); sb.append(" L="+L+" {"); for(int j = 0; j < L; j++) { sb.append(D.attribute(j).name()+" "); } sb.append("}"); return sb.toString(); }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int L = D.classIndex(); if(getDebug()) System.out.print("Creating "+L+" models ("+m_Classifier.getClass().getName()+"): "); m_MultiClassifiers = AbstractClassifier.makeCopies(m_Classifier,L); m_InstancesTemplates = new Instances[L]; for(int j = 0; j < L; j++) { //Select only class attribute 'j' Instances D_j = F.keepLabels(new Instances(D),L,new int[]{j}); D_j.setClassIndex(0); //Build the classifier for that class m_MultiClassifiers[j].buildClassifier(D_j); if(getDebug()) System.out.print(" " + (D_j.classAttribute().name())); m_InstancesTemplates[j] = new Instances(D_j, 0); } }
/** * Returns the contents of an item set as a delimited string. * * @param instances contains the relevant header information * @param outerDelim the outer delimiter * @param innerDelim the inner delimiter * @return string describing the item set */ public String toString(Instances instances, char outerDelim, char innerDelim) { StringBuffer text = new StringBuffer(); for (int i = 0; i < instances.numAttributes(); i++) { if (m_items[i] != -1) { text.append(instances.attribute(i).name()).append('=') .append(instances.attribute(i).value(m_items[i])).append(innerDelim); } } int n = text.length(); if (n > 0) { text.setCharAt(n - 1, outerDelim); } else { if (outerDelim != ' ' || innerDelim != ' ') { text.append(outerDelim); } } text.append(m_counter); return text.toString(); }
private static ArrayList<String> getLabels(Instances data) { int numLabels = data.classIndex(); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < numLabels; i++) { list.add(data.attribute(i).name()); } return list; } }
public static List<String> instanceHeaderToAttributeNameList(Instances header) { List<String> attNames = new ArrayList<String>(); for (int i = 0; i < header.numAttributes(); i++) { attNames.add(header.attribute(i).name()); } return attNames; }
public static final String toDebugString(Instances D) { int L = D.classIndex(); StringBuilder sb = new StringBuilder(); sb.append("D="+D.numInstances()); sb.append(" L="+L+" {"); for(int j = 0; j < L; j++) { sb.append(D.attribute(j).name()+" "); } sb.append("}"); return sb.toString(); }
@Override public void buildClassifier(Instances D) throws Exception { testCapabilities(D); int L = D.classIndex(); if(getDebug()) System.out.print("Creating "+L+" models ("+m_Classifier.getClass().getName()+"): "); m_MultiClassifiers = AbstractClassifier.makeCopies(m_Classifier,L); m_Templates = new Instances[L]; for(int j = 0; j < L; j++) { //Select only class attribute 'j' m_Templates[j] = MLUtils.keepAttributesAt(new Instances(D),new int[]{j},L); m_Templates[j].setClassIndex(0); //Build the classifier for that class m_MultiClassifiers[j].buildClassifier(m_Templates[j]); if(getDebug()) System.out.print(" " + (m_Templates[j].classAttribute().name())); m_Templates[j] = new Instances(m_Templates[j], 0); } }
/** * Outputs description of classifier as a string. * @return the description */ public String toString() { if (m_Weights == null) { return "No model has been built yet."; } StringBuffer result = new StringBuffer(); result.append("Fisher's Linear Discriminant Analysis\n\n"); result.append("Threshold: " + m_Threshold + "\n\n"); result.append("Weights:\n\n"); int index = 0; for (int i = 0; i < m_Data.numAttributes(); i++) { if (i != m_Data.classIndex()) { result.append(m_Data.attribute(i).name() + ": \t"); double weight = m_Weights.get(index++); if (weight >= 0) { result.append(" "); } result.append(weight + "\n"); } } return result.toString(); }