Java Code Examples for weka.core.Attribute#NUMERIC
The following examples show how to use
weka.core.Attribute#NUMERIC .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManhattanDataObject.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Performs manhattan-distance-calculation between two given values * @param index of the attribute within the DataObject's instance * @param v value_1 * @param v1 value_2 * @return double norm-distance between value_1 and value_2 */ private double computeDistance(int index, double v, double v1) { switch (getInstance().attribute(index).type()) { case Attribute.NOMINAL: return (Utils.isMissingValue(v) || Utils.isMissingValue(v1) || ((int) v != (int) v1)) ? 1 : 0; case Attribute.NUMERIC: if (Utils.isMissingValue(v) || Utils.isMissingValue(v1)) { if (Utils.isMissingValue(v) && Utils.isMissingValue(v1)) return 1; else { return (Utils.isMissingValue(v)) ? norm(v1, index) : norm(v, index); } } else return norm(v, index) - norm(v1, index); default: return 0; } }
Example 2
Source File: RDG1.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Chooses randomly the attributes that get datatyp numeric. * @param random the random number generator to use * @return list of integer values, with one value for each attribute, * and each value set to Attribut.NOMINAL or Attribut.NUMERIC */ private int[] defineNumeric(Random random) { int[] num = new int [getNumAttributes()]; // initialize for (int i = 0; i < num.length; i++) num[i] = Attribute.NOMINAL; int numNum = 0; for (int i = 0; (numNum < getNumNumeric()) && (i < getNumAttributes() * 5); i++) { int maybeNext = (int) (random.nextDouble() * (double) num.length); if (num[maybeNext] != Attribute.NUMERIC) { num[maybeNext] = Attribute.NUMERIC; numNum++; } } return num; }
Example 3
Source File: DataTableModel.java From meka with GNU General Public License v3.0 | 6 votes |
/** * returns the most specific superclass for all the cell values in the column * (always String) * * @param columnIndex the column index * @return the class of the column */ @Override public Class<?> getColumnClass(int columnIndex) { Class<?> result; result = null; if ((columnIndex >= 0) && (columnIndex < getColumnCount())) { if (columnIndex == 0) { result = Integer.class; } else if (getType(columnIndex) == Attribute.NUMERIC) { result = Double.class; } else { result = String.class; // otherwise no input of "?"!!! } } return result; }
Example 4
Source File: HyperPipes.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Creates the HyperPipe as the n-dimensional parallel-piped * with minimum volume containing all the points in * pointSet. * * @param instances all instances belonging to the same class * @throws Exception if missing values are found */ public HyperPipe(Instances instances) throws Exception { m_NumericBounds = new double [instances.numAttributes()][]; m_NominalBounds = new boolean [instances.numAttributes()][]; for (int i = 0; i < instances.numAttributes(); i++) { switch (instances.attribute(i).type()) { case Attribute.NUMERIC: m_NumericBounds[i] = new double [2]; m_NumericBounds[i][0] = Double.POSITIVE_INFINITY; m_NumericBounds[i][1] = Double.NEGATIVE_INFINITY; break; case Attribute.NOMINAL: m_NominalBounds[i] = new boolean [instances.attribute(i).numValues()]; break; default: throw new UnsupportedAttributeTypeException("Cannot process string attributes!"); } } for (int i = 0; i < instances.numInstances(); i++) { addInstance(instances.instance(i)); } }
Example 5
Source File: ARAMNetworkSparseHT_Strange.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Classifies the given test instance. The instance has to belong to a * dataset when it's being classified. Note that a classifier MUST * implement either this or distributionForInstance(). * * @param instance the instance to be classified * @return the predicted most likely class for the instance or * Instance.missingValue() if no prediction is made * @exception Exception if an error occurred during the prediction */ public double classifyInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted"); } switch (instance.classAttribute().type()) { case Attribute.NOMINAL: double max = 0; int maxIndex = 0; for (int i = 0; i < dist.length; i++) { if (dist[i] > max) { maxIndex = i; max = dist[i]; } } if (max > 0) { return maxIndex; } else { //return Instance.missingValue(); } case Attribute.NUMERIC: return dist[0]; default: return -1; } }
Example 6
Source File: RemoveType.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Sets the attribute type to be deleted by the filter. * * @param typeString a String representing the new type the filter should delete */ protected void setAttributeTypeString(String typeString) { typeString = typeString.toLowerCase(); if (typeString.equals("nominal")) m_attTypeToDelete = Attribute.NOMINAL; else if (typeString.equals("numeric")) m_attTypeToDelete = Attribute.NUMERIC; else if (typeString.equals("string")) m_attTypeToDelete = Attribute.STRING; else if (typeString.equals("date")) m_attTypeToDelete = Attribute.DATE; else if (typeString.equals("relational")) m_attTypeToDelete = Attribute.RELATIONAL; }
Example 7
Source File: Add.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { Vector<String> result; result = new Vector<String>(); if (m_AttributeType != Attribute.NUMERIC) { result.add("-T"); result.add("" + getAttributeType()); } result.add("-N"); result.add(Utils.backQuoteChars(getAttributeName())); if (m_AttributeType == Attribute.NOMINAL) { result.add("-L"); result.add(getNominalLabels()); } else if (m_AttributeType == Attribute.NOMINAL) { result.add("-F"); result.add(getDateFormat()); } result.add("-C"); result.add("" + getAttributeIndex()); return result.toArray(new String[result.size()]); }
Example 8
Source File: ARAMNetworkSparseV.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Classifies the given test instance. The instance has to belong to a * dataset when it's being classified. Note that a classifier MUST * implement either this or distributionForInstance(). * * @param instance the instance to be classified * @return the predicted most likely class for the instance or * Instance.missingValue() if no prediction is made * @exception Exception if an error occurred during the prediction */ public double classifyInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted"); } switch (instance.classAttribute().type()) { case Attribute.NOMINAL: double max = 0; int maxIndex = 0; for (int i = 0; i < dist.length; i++) { if (dist[i] > max) { maxIndex = i; max = dist[i]; } } if (max > 0) { return maxIndex; } else { //return Instance.missingValue(); } case Attribute.NUMERIC: return dist[0]; default: return -1; } }
Example 9
Source File: WARAM.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Classifies the given test instance. The instance has to belong to a * dataset when it's being classified. Note that a classifier MUST * implement either this or distributionForInstance(). * * @param instance the instance to be classified * @return the predicted most likely class for the instance or * Instance.missingValue() if no prediction is made * @exception Exception if an error occurred during the prediction */ public double classifyInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted"); } switch (instance.classAttribute().type()) { case Attribute.NOMINAL: double max = 0; int maxIndex = 0; for (int i = 0; i < dist.length; i++) { if (dist[i] > max) { maxIndex = i; max = dist[i]; } } if (max > 0) { return maxIndex; } else { //return Instance.missingValue(); } case Attribute.NUMERIC: return dist[0]; default: return -1; } }
Example 10
Source File: CheckEstimator.java From tsml with GNU General Public License v3.0 | 5 votes |
int getSetType() throws Exception { int sum = 0; int type = -1; if (nominal) { sum ++; type = Attribute.NOMINAL; } if (numeric) { sum ++; type = Attribute.NUMERIC; } if (string) { sum ++; type = Attribute.STRING; } if (date) { sum ++; type = Attribute.DATE; } if (relational) { sum ++; type = Attribute.RELATIONAL; } if (sum > 1) throw new Exception("Expected to have only one type set used wrongly."); if (type < 0) throw new Exception("No type set."); return type; }
Example 11
Source File: ARAMNetworkSparse.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Classifies the given test instance. The instance has to belong to a * dataset when it's being classified. Note that a classifier MUST * implement either this or distributionForInstance(). * * @param instance the instance to be classified * @return the predicted most likely class for the instance or * Instance.missingValue() if no prediction is made * @exception Exception if an error occurred during the prediction */ public double classifyInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted"); } switch (instance.classAttribute().type()) { case Attribute.NOMINAL: double max = 0; int maxIndex = 0; for (int i = 0; i < dist.length; i++) { if (dist[i] > max) { maxIndex = i; max = dist[i]; } } if (max > 0) { return maxIndex; } else { //return Instance.missingValue(); } case Attribute.NUMERIC: return dist[0]; default: return -1; } }
Example 12
Source File: CheckClassifier.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Print out a short summary string for the dataset characteristics * * @param nominalPredictor true if nominal predictor attributes are present * @param numericPredictor true if numeric predictor attributes are present * @param stringPredictor true if string predictor attributes are present * @param datePredictor true if date predictor attributes are present * @param relationalPredictor true if relational predictor attributes are present * @param multiInstance whether multi-instance is needed * @param classType the class type (NUMERIC, NOMINAL, etc.) */ protected void printAttributeSummary(boolean nominalPredictor, boolean numericPredictor, boolean stringPredictor, boolean datePredictor, boolean relationalPredictor, boolean multiInstance, int classType) { String str = ""; if (numericPredictor) str += " numeric"; if (nominalPredictor) { if (str.length() > 0) str += " &"; str += " nominal"; } if (stringPredictor) { if (str.length() > 0) str += " &"; str += " string"; } if (datePredictor) { if (str.length() > 0) str += " &"; str += " date"; } if (relationalPredictor) { if (str.length() > 0) str += " &"; str += " relational"; } str += " predictors)"; switch (classType) { case Attribute.NUMERIC: str = " (numeric class," + str; break; case Attribute.NOMINAL: str = " (nominal class," + str; break; case Attribute.STRING: str = " (string class," + str; break; case Attribute.DATE: str = " (date class," + str; break; case Attribute.RELATIONAL: str = " (relational class," + str; break; } print(str); }
Example 13
Source File: CollectiveClassifierPanel.java From collective-classification-weka-package with GNU General Public License v3.0 | 4 votes |
/** * Tells the panel to use a new set of instances. * * @param inst a set of Instances */ public void setInstances(Instances inst) { m_Instances = inst; String[] attribNames = new String [m_Instances.numAttributes()]; for (int i = 0; i < attribNames.length; i++) { String type = ""; switch (m_Instances.attribute(i).type()) { case Attribute.NOMINAL: type = "(Nom) "; break; case Attribute.NUMERIC: type = "(Num) "; break; case Attribute.STRING: type = "(Str) "; break; case Attribute.DATE: type = "(Dat) "; break; case Attribute.RELATIONAL: type = "(Rel) "; break; default: type = "(???) "; } attribNames[i] = type + m_Instances.attribute(i).name(); } m_ClassCombo.setModel(new DefaultComboBoxModel(attribNames)); if (attribNames.length > 0) { if (inst.classIndex() == -1) m_ClassCombo.setSelectedIndex(attribNames.length - 1); else m_ClassCombo.setSelectedIndex(inst.classIndex()); m_EvalCombo.setEnabled(true); m_ClassCombo.setEnabled(true); m_CVPanel.setEnabled(true); m_SplitPanel.setEnabled(true); m_TestPanel.setEnabled(true); m_StartBut.setEnabled(m_RunThread == null); m_StopBut.setEnabled(m_RunThread != null); } else { m_StartBut.setEnabled(false); m_StopBut.setEnabled(false); } }
Example 14
Source File: DataTableModel.java From meka with GNU General Public License v3.0 | 4 votes |
/** * returns the value for the cell at columnindex and rowIndex * * @param rowIndex the row index * @param columnIndex the column index * @return the value at the position */ @Override public Object getValueAt(int rowIndex, int columnIndex) { Object result; String tmp; String key; boolean modified; result = null; key = rowIndex + "-" + columnIndex; if ((rowIndex >= 0) && (rowIndex < getRowCount()) && (columnIndex >= 0) && (columnIndex < getColumnCount())) { if (columnIndex == 0) { result = new Integer(rowIndex + 1); } else { if (isMissingAt(rowIndex, columnIndex)) { result = null; } else { if (m_Cache.containsKey(key)) { result = m_Cache.get(key); } else { switch (getType(columnIndex)) { case Attribute.DATE: case Attribute.NOMINAL: case Attribute.STRING: case Attribute.RELATIONAL: result = m_Data.instance(rowIndex).stringValue(columnIndex - 1); break; case Attribute.NUMERIC: result = new Double(m_Data.instance(rowIndex).value(columnIndex - 1)); break; default: result = "-can't display-"; } if (getType(columnIndex) != Attribute.NUMERIC) { if (result != null) { tmp = result.toString(); modified = false; // fix html tags, otherwise Java parser hangs if ((tmp.indexOf('<') > -1) || (tmp.indexOf('>') > -1)) { tmp = tmp.replace("<", "("); tmp = tmp.replace(">", ")"); modified = true; } // does it contain "\n" or "\r"? -> replace with red html tag if ((tmp.indexOf("\n") > -1) || (tmp.indexOf("\r") > -1)) { tmp = tmp.replaceAll("\\r\\n", "<font color=\"red\"><b>\\\\r\\\\n</b></font>"); tmp = tmp.replaceAll("\\r", "<font color=\"red\"><b>\\\\r</b></font>"); tmp = tmp.replaceAll("\\n", "<font color=\"red\"><b>\\\\n</b></font>"); tmp = "<html>" + tmp + "</html>"; modified = true; } result = tmp; if (modified) { m_Cache.put(key, tmp); } } } } } } } return result; }
Example 15
Source File: CheckAttributeSelection.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Print out a short summary string for the dataset characteristics * * @param nominalPredictor true if nominal predictor attributes are present * @param numericPredictor true if numeric predictor attributes are present * @param stringPredictor true if string predictor attributes are present * @param datePredictor true if date predictor attributes are present * @param relationalPredictor true if relational predictor attributes are present * @param multiInstance whether multi-instance is needed * @param classType the class type (NUMERIC, NOMINAL, etc.) */ protected void printAttributeSummary(boolean nominalPredictor, boolean numericPredictor, boolean stringPredictor, boolean datePredictor, boolean relationalPredictor, boolean multiInstance, int classType) { String str = ""; if (numericPredictor) str += " numeric"; if (nominalPredictor) { if (str.length() > 0) str += " &"; str += " nominal"; } if (stringPredictor) { if (str.length() > 0) str += " &"; str += " string"; } if (datePredictor) { if (str.length() > 0) str += " &"; str += " date"; } if (relationalPredictor) { if (str.length() > 0) str += " &"; str += " relational"; } str += " predictors)"; switch (classType) { case Attribute.NUMERIC: str = " (numeric class," + str; break; case Attribute.NOMINAL: str = " (nominal class," + str; break; case Attribute.STRING: str = " (string class," + str; break; case Attribute.DATE: str = " (date class," + str; break; case Attribute.RELATIONAL: str = " (relational class," + str; break; } print(str); }
Example 16
Source File: CheckKernel.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Print out a short summary string for the dataset characteristics * * @param nominalPredictor true if nominal predictor attributes are present * @param numericPredictor true if numeric predictor attributes are present * @param stringPredictor true if string predictor attributes are present * @param datePredictor true if date predictor attributes are present * @param relationalPredictor true if relational predictor attributes are present * @param multiInstance whether multi-instance is needed * @param classType the class type (NUMERIC, NOMINAL, etc.) */ protected void printAttributeSummary(boolean nominalPredictor, boolean numericPredictor, boolean stringPredictor, boolean datePredictor, boolean relationalPredictor, boolean multiInstance, int classType) { String str = ""; if (numericPredictor) str += " numeric"; if (nominalPredictor) { if (str.length() > 0) str += " &"; str += " nominal"; } if (stringPredictor) { if (str.length() > 0) str += " &"; str += " string"; } if (datePredictor) { if (str.length() > 0) str += " &"; str += " date"; } if (relationalPredictor) { if (str.length() > 0) str += " &"; str += " relational"; } str += " predictors)"; switch (classType) { case Attribute.NUMERIC: str = " (numeric class," + str; break; case Attribute.NOMINAL: str = " (nominal class," + str; break; case Attribute.STRING: str = " (string class," + str; break; case Attribute.DATE: str = " (date class," + str; break; case Attribute.RELATIONAL: str = " (relational class," + str; break; } print(str); }
Example 17
Source File: CheckEstimator.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Print out a short summary string for the dataset characteristics * * @param attrTypes the attribute types used (NUMERIC, NOMINAL, etc.) * @param classType the class type (NUMERIC, NOMINAL, etc.) */ protected void printAttributeSummary(AttrTypes attrTypes, int classType) { String str = ""; if (attrTypes.numeric) str += " numeric"; if (attrTypes.nominal) { if (str.length() > 0) str += " &"; str += " nominal"; } if (attrTypes.string) { if (str.length() > 0) str += " &"; str += " string"; } if (attrTypes.date) { if (str.length() > 0) str += " &"; str += " date"; } if (attrTypes.relational) { if (str.length() > 0) str += " &"; str += " relational"; } str += " attributes)"; switch (classType) { case Attribute.NUMERIC: str = " (numeric class," + str; break; case Attribute.NOMINAL: str = " (nominal class," + str; break; case Attribute.STRING: str = " (string class," + str; break; case Attribute.DATE: str = " (date class," + str; break; case Attribute.RELATIONAL: str = " (relational class," + str; break; } print(str); }
Example 18
Source File: FarthestFirst.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Computes the difference between two given attribute * values. */ protected double difference(int index, double val1, double val2) { switch (m_instances.attribute(index).type()) { case Attribute.NOMINAL: // If attribute is nominal if (Utils.isMissingValue(val1) || Utils.isMissingValue(val2) || ((int)val1 != (int)val2)) { return 1; } else { return 0; } case Attribute.NUMERIC: // If attribute is numeric if (Utils.isMissingValue(val1) || Utils.isMissingValue(val2)) { if (Utils.isMissingValue(val1) && Utils.isMissingValue(val2)) { return 1; } else { double diff; if (Utils.isMissingValue(val2)) { diff = norm(val1, index); } else { diff = norm(val2, index); } if (diff < 0.5) { diff = 1.0 - diff; } return diff; } } else { return norm(val1, index) - norm(val2, index); } default: return 0; } }
Example 19
Source File: CheckEstimator.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Print out a short summary string for the dataset characteristics * * @param attrType the attribute type (NUMERIC, NOMINAL, etc.) * @param classType the class type (NUMERIC, NOMINAL, etc.) */ protected void printAttributeSummary(int attrType, int classType) { String str = ""; switch (attrType) { case Attribute.NUMERIC: str = " numeric" + str; break; case Attribute.NOMINAL: str = " nominal" + str; break; case Attribute.STRING: str = " string" + str; break; case Attribute.DATE: str = " date" + str; break; case Attribute.RELATIONAL: str = " relational" + str; break; } str += " attribute(s))"; switch (classType) { case Attribute.NUMERIC: str = " (numeric class," + str; break; case Attribute.NOMINAL: str = " (nominal class," + str; break; case Attribute.STRING: str = " (string class," + str; break; case Attribute.DATE: str = " (date class," + str; break; case Attribute.RELATIONAL: str = " (relational class," + str; break; } print(str); }
Example 20
Source File: CheckEstimator.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Run a battery of tests for a given class attribute type * * @param classType true if the class attribute should be numeric * @param estTypes types the estimator is, like incremental, weighted, supervised etc * @return attribute types estimator can work with */ protected AttrTypes testsPerClassType(int classType, EstTypes estTypes) { // in none of the estimators yet is the estimation depending on the class type // since this could change the basic structure taken from checkclassifiers is kept here // test A: simple test - if can estimate AttrTypes attrTypes = new AttrTypes(); AttrTypes at = new AttrTypes(Attribute.NOMINAL); attrTypes.nominal = canEstimate(at, estTypes.supervised, classType)[0]; at = new AttrTypes(Attribute.NUMERIC); attrTypes.numeric = canEstimate(at, estTypes.supervised, classType)[0]; attrTypes.string = false; attrTypes.date = false; attrTypes.relational = false; // if (!multiInstance) // PRel = canEstimate(false, false, false, false, true, classType)[0]; // else // PRel = false; // one of the attribute types succeeded if (attrTypes.oneIsSet()) { Vector attributesSet = attrTypes.getVectorOfAttrTypes(); // make tests for each attribute for (int i = 0; i < attributesSet.size(); i++) { AttrTypes workAttrTypes = new AttrTypes(((Integer) attributesSet.elementAt(i)).intValue()); // test B: weights change estimate or not if (estTypes.weighted) instanceWeights(workAttrTypes, classType); if (classType == Attribute.NOMINAL) { int numClasses = 4; canHandleNClasses(workAttrTypes, numClasses); } // tests with class not the last attribute and the attribute not the first // if (!multiInstance) { int numAtt = 4; canHandleClassAsNthAttribute(workAttrTypes, numAtt, 0, classType, 1); //TODOTODOcanHandleAttrAsNthAttribute(workAttrTypes, numAtt, 2, classType); //} canHandleZeroTraining(workAttrTypes, classType); boolean handleMissingAttributes = canHandleMissing(workAttrTypes, classType, true, false, 20)[0]; if (handleMissingAttributes) canHandleMissing(workAttrTypes, classType, true, false, 100); boolean handleMissingClass = canHandleMissing(workAttrTypes, classType, false, true, 20)[0]; if (handleMissingClass) canHandleMissing(workAttrTypes, classType, false, true, 100); correctBuildInitialisation(workAttrTypes, classType); datasetIntegrity(workAttrTypes, classType, handleMissingAttributes, handleMissingClass); if (estTypes.incremental) incrementingEquality(workAttrTypes, classType); } } return attrTypes; }