List of usage examples for weka.core Instance value
public double value(Attribute att);
From source file:de.unidue.langtech.grading.tc.ClusterTrainTask.java
License:Open Source License
private ConditionalFrequencyDistribution<Integer, String> getClusterCfd(Map<Integer, Set<Integer>> clusterMap, Instances data, List<String> outcomeValues) { ConditionalFrequencyDistribution<Integer, String> clusterAssignments = new ConditionalFrequencyDistribution<Integer, String>(); for (Integer clusterId : clusterMap.keySet()) { for (Integer offset : clusterMap.get(clusterId)) { // get instance ID from instance Instance instance = data.get(offset); Double classOffset = new Double(instance.value(data.classAttribute())); String label = outcomeValues.get(classOffset.intValue()); clusterAssignments.addSample(clusterId, label); }//from ww w. j a va 2 s . c o m } return clusterAssignments; }
From source file:de.uniheidelberg.cl.swp.mlprocess.AblationTesting.java
License:Apache License
/** * Determines the attribute value for a Instance object and the specified attribute name. * /*w w w.jav a 2 s .c o m*/ * @param inst The instance object from which the value is extracted. * @param featureName The name of the attribute. * @return A double representation of the value used by WEKA. */ private double getAttributeValue(Instance inst, String featureName) { for (int i = 0; i < inst.numAttributes(); i++) { if (inst.attribute(i).name().equals(featureName)) return inst.value(i); } return 0; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.util.WeightedEditDistance.java
License:Open Source License
/** * Updates the ranges given a new instance. * //w w w .j av a 2 s . c o m * @param instance the new instance * @param ranges low, high and width values for all attributes * @return the updated ranges */ public double[][] updateRanges(Instance instance, double[][] ranges) { // updateRangesFirst must have been called on ranges for (int j = 0; j < ranges.length; j++) { double value = instance.value(j); if (!((ProcessInstance) instance).isStringMissing(j)) { if (value < ranges[j][R_MIN]) { ranges[j][R_MIN] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } else { if (instance.value(j) > ranges[j][R_MAX]) { ranges[j][R_MAX] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } } } } return ranges; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.util.WeightedEditDistance.java
License:Open Source License
/** * Updates the minimum and maximum and width values for all the attributes * based on a new instance./*from ww w. j a v a2 s.c om*/ * * @param instance the new instance * @param numAtt number of attributes in the model * @param ranges low, high and width values for all attributes */ public void updateRanges(Instance instance, int numAtt, double[][] ranges) { // updateRangesFirst must have been called on ranges for (int j = 0; j < numAtt; j++) { double value = instance.value(j); if (!((ProcessInstance) instance).isMissing(j)) { if (value < ranges[j][R_MIN]) { ranges[j][R_MIN] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; if (value > ranges[j][R_MAX]) { //if this is the first value that is ranges[j][R_MAX] = value; //not missing. The,0 ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } } else { if (value > ranges[j][R_MAX]) { ranges[j][R_MAX] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } } } } }
From source file:de.uni_potsdam.hpi.bpt.promnicat.util.WeightedEditDistance.java
License:Open Source License
/** * Used to initialize the ranges. For this the values of the first * instance is used to save time.// w ww . j av a 2 s. c o m * Sets low and high to the values of the first instance and * width to zero. * * @param instance the new instance * @param numAtt number of attributes in the model * @param ranges low, high and width values for all attributes */ public void updateRangesFirst(Instance instance, int numAtt, double[][] ranges) { for (int j = 0; j < numAtt; j++) { if (!((ProcessInstance) instance).isStringMissing(j)) { ranges[j][R_MIN] = instance.value(j); ranges[j][R_MAX] = instance.value(j); ranges[j][R_WIDTH] = 0.0; } else { // if value was missing ranges[j][R_MIN] = Double.POSITIVE_INFINITY; ranges[j][R_MAX] = -Double.POSITIVE_INFINITY; ranges[j][R_WIDTH] = Double.POSITIVE_INFINITY; } } }
From source file:de.uni_potsdam.hpi.bpt.promnicat.util.WeightedEditDistance.java
License:Open Source License
/** * Test if an instance is within the given ranges. * //from ww w . j a v a 2 s. c om * @param instance the instance * @param ranges the ranges the instance is tested to be in * @return true if instance is within the ranges */ public boolean inRanges(Instance instance, double[][] ranges) { boolean isIn = true; // updateRangesFirst must have been called on ranges for (int j = 0; isIn && (j < ranges.length); j++) { if (!((ProcessInstance) instance).isStringMissing(j)) { double value = instance.value(j); isIn = value <= ranges[j][R_MAX]; if (isIn) isIn = value >= ranges[j][R_MIN]; } } return isIn; }
From source file:decisiontree.ID3tree.java
private double calculateEntropy(ArrayList<Instance> aList, int attr, int index) { Instance tempInst; int numInst = aList.size(); int[] numAttr; double ent = 0.0; double temp;//from ww w . ja v a 2s . c o m numAttr = new int[attr]; Arrays.fill(numAttr, 0); // Count number of classes for (int i = 0; i < numInst; i++) { tempInst = aList.get(i); for (int j = 0; j < attr - 1; j++) { if (tempInst.value(index) == j) numAttr[j] += 1; } } //System.out.println(attr); for (int j = 0; j < attr - 1; j++) { temp = numAttr[j] / (double) numInst; if (Double.isNaN(temp)) ent -= 0.0; else ent -= (temp * (Math.log(temp) / Math.log(2))); } return ent; }
From source file:decisiontree.MyC45.java
/** * Splits a dataset according to the values of a nominal attribute. * * @param data the data which is to be split * @param att the attribute to be used for splitting * @return the sets of instances produced by the split *//*from w w w . ja va2s. com*/ private Instances[] splitData(Instances data, Attribute att) { Instances[] splitData = new Instances[att.numValues()]; for (int j = 0; j < att.numValues(); j++) { splitData[j] = new Instances(data, data.numInstances()); } Enumeration instEnum = data.enumerateInstances(); while (instEnum.hasMoreElements()) { Instance inst = (Instance) instEnum.nextElement(); splitData[(int) inst.value(att)].add(inst); } for (int i = 0; i < splitData.length; i++) { splitData[i].compactify(); } return splitData; }
From source file:decisiontree.MyC45.java
/** * Splits a dataset according to the values of a numeric attribute. * * @param data the data which is to be split * @param att the attribute to be used for splitting * @return the sets of instances produced by the split *//*from w w w. j av a 2 s. c o m*/ private Instances[] splitData(Instances data, Attribute att, double threshold) { Instances[] splitData = new Instances[2]; for (int i = 0; i < 2; i++) { splitData[i] = new Instances(data, data.numInstances()); } Enumeration instEnum = data.enumerateInstances(); while (instEnum.hasMoreElements()) { Instance inst = (Instance) instEnum.nextElement(); if (inst.value(att) >= threshold) { inst.setValue(att, threshold); splitData[1].add(inst); } else { inst.setValue(att, 0); splitData[0].add(inst); } } for (int i = 0; i < splitData.length; i++) { splitData[i].compactify(); } return splitData; }
From source file:decisiontree.MyC45.java
/** * Classifies a given test instance using the decision tree. * * @param instance the instance to be classified * @return the classification/* w w w . ja v a 2 s . c om*/ */ public double classifyInstance(Instance instance) { if (m_Attribute == null) { return m_ClassValue; } else { return m_Successors[(int) instance.value(m_Attribute)].classifyInstance(instance); } }