/** * SetLabelsMissing - Set all (L) labels in x to missing. */ public static Instance setLabelsMissing(Instance x, int L) { for(int j = 0; j < L ; j++) { x.setMissing(j); } return x; }
/** * SetLabelsMissing - Set all (L) labels in x to missing. */ public static Instance setLabelsMissing(Instance x, int L) { for(int j = 0; j < L ; j++) { x.setMissing(j); } return x; }
/** * SetLabelsMissing - Set all (L) labels in x to missing. */ public static Instance setLabelsMissing(Instance x, int L) { for(int j = 0; j < L ; j++) { x.setMissing(j); } return x; }
/** * Creates a Weka Instance object * @param values feature vector * @param dataset example weka dataset for feature counts/types * @return */ public static Instance makeCompatible(Vector<String> values, Instances dataset) { Instance retInstance=new Instance(values.size()+1); // dataset knows about possible nominal values retInstance.setDataset(dataset); for (int i = 0; i < values.size(); i++) { // check for existence of nominal values, otherwise convert to "missing": unknown vocabulary as features if (values.get(i)==null) {retInstance.setMissing(i);} else if (dataset.attribute(i).indexOfValue(values.get(i))>=0) {// ((possValues[i]!=null)&&(possValues[i].containsKey(values[i]))) { retInstance.setValue(i, values.get(i)); } else {retInstance.setMissing(i);} } return retInstance; }
/** * Add missing values to a dataset. * * @param data the instances to add missing values to * @param level the level of missing values to add (if positive, this is the * probability that a value will be set to missing, if negative all * but one value will be set to missing (not yet implemented)) * @param predictorMissing if true, predictor attributes will be modified */ protected void addMissing(Instances data, int level, boolean predictorMissing) { Random random = new Random(1); for (int i = 0; i < data.numInstances(); i++) { Instance current = data.instance(i); for (int j = 0; j < data.numAttributes(); j++) { if (predictorMissing) { if (random.nextInt(100) < level) { current.setMissing(j); } } } } }
/** * Add missing values to a dataset. * * @param data the instances to add missing values to * @param level the level of missing values to add (if positive, this is the * probability that a value will be set to missing, if negative all * but one value will be set to missing (not yet implemented)) * @param predictorMissing if true, predictor attributes will be modified */ protected void addMissing(Instances data, int level, boolean predictorMissing) { Random random = new Random(1); for (int i = 0; i < data.numInstances(); i++) { Instance current = data.instance(i); for (int j = 0; j < data.numAttributes(); j++) { if (predictorMissing) { if (random.nextInt(100) < level) { current.setMissing(j); } } } } }
/** * SetLabelsMissing - Set all labels in D to missing. */ public static Instances setLabelsMissing(Instances D) { int L = D.classIndex(); for(int i = 0; i < D.numInstances(); i++) { for(int j = 0; j < L ; j++) { D.instance(i).setMissing(j); } } return D; }
/** * SetLabelsMissing - Set all labels in D to missing. */ public static Instances setLabelsMissing(Instances D) { int L = D.classIndex(); for(int i = 0; i < D.numInstances(); i++) { for(int j = 0; j < L ; j++) { D.instance(i).setMissing(j); } } return D; }
/** * SetLabelsMissing - Set all labels in D to missing. */ public static Instances setLabelsMissing(Instances D) { int L = D.classIndex(); for(int i = 0; i < D.numInstances(); i++) { for(int j = 0; j < L ; j++) { D.instance(i).setMissing(j); } } return D; }
/** * Add missing values to a dataset. * * @param data the instances to add missing values to * @param level the level of missing values to add (if positive, this is the * probability that a value will be set to missing, if negative all * but one value will be set to missing (not yet implemented)) * @param attributeMissing if true, attributes will be modified * @param classMissing if true, the class attribute will be modified * @param attrIndex index of the attribute */ protected void addMissing(Instances data, int level, boolean attributeMissing, boolean classMissing, int attrIndex) { int classIndex = data.classIndex(); Random random = new Random(1); for (int i = 0; i < data.numInstances(); i++) { Instance current = data.instance(i); for (int j = 0; j < data.numAttributes(); j++) { if (((j == classIndex) && classMissing) || ((j == attrIndex) && attributeMissing)) { if (random.nextInt(100) < level) { current.setMissing(j); } } } } }
/** * Add missing values to a dataset. * * @param data the instances to add missing values to * @param level the level of missing values to add (if positive, this * is the probability that a value will be set to missing, if negative * all but one value will be set to missing (not yet implemented)) * @param predictorMissing if true, predictor attributes will be modified * @param classMissing if true, the class attribute will be modified */ protected void addMissing(Instances data, int level, boolean predictorMissing, boolean classMissing) { int classIndex = data.classIndex(); Random random = new Random(1); for (int i = 0; i < data.numInstances(); i++) { Instance current = data.instance(i); for (int j = 0; j < data.numAttributes(); j++) { if (((j == classIndex) && classMissing) || ((j != classIndex) && predictorMissing)) { if (random.nextInt(100) < level) current.setMissing(j); } } } }
/** * Add missing values to a dataset. * * @param data the instances to add missing values to * @param level the level of missing values to add (if positive, this * is the probability that a value will be set to missing, if negative * all but one value will be set to missing (not yet implemented)) * @param predictorMissing if true, predictor attributes will be modified * @param classMissing if true, the class attribute will be modified */ protected void addMissing(Instances data, int level, boolean predictorMissing, boolean classMissing) { int classIndex = data.classIndex(); Random random = new Random(1); for (int i = 0; i < data.numInstances(); i++) { Instance current = data.instance(i); for (int j = 0; j < data.numAttributes(); j++) { if (((j == classIndex) && classMissing) || ((j != classIndex) && predictorMissing)) { if (random.nextInt(100) < level) current.setMissing(j); } } } }
/** * Add missing values to a dataset. * * @param data the instances to add missing values to * @param level the level of missing values to add (if positive, this is the * probability that a value will be set to missing, if negative all * but one value will be set to missing (not yet implemented)) * @param attributeMissing if true, attributes will be modified * @param classMissing if true, the class attribute will be modified * @param attrIndex index of the attribute */ protected void addMissing(Instances data, int level, boolean attributeMissing, boolean classMissing, int attrIndex) { int classIndex = data.classIndex(); Random random = new Random(1); for (int i = 0; i < data.numInstances(); i++) { Instance current = data.instance(i); for (int j = 0; j < data.numAttributes(); j++) { if (((j == classIndex) && classMissing) || ((j == attrIndex) && attributeMissing)) { if (random.nextInt(100) < level) { current.setMissing(j); } } } } }
@Override public String classify(Instance instance) throws Exception { weka.core.Instance wekaInstance = new weka.core.Instance(wekaTrainingData.numAttributes()); wekaInstance.setDataset(wekaTrainingData); double[] histogramPercent = instance.getHistogramPercent(); for (int i = 0; i < histogramPercent.length; i++) { wekaInstance.setValue(i, histogramPercent[i]); } wekaInstance.setMissing(wekaTrainingData.attribute("class")); double wekaClassification = classifier.classifyInstance(wekaInstance); String classification = wekaTrainingData.attribute("class").value((int)wekaClassification); return classification; }
newInstance.setValue(i, y); } else { newInstance.setMissing(i);
@Override public Instance transformInstance(Instance x) throws Exception{ Instances tmpInst = new Instances(x.dataset()); tmpInst.delete(); tmpInst.add(x); Instances features = this.extractPart(tmpInst, false); Instances pseudoLabels = new Instances(this.compressedMatrix); Instance tmpin = pseudoLabels.instance(0); pseudoLabels.delete(); pseudoLabels.add(tmpin); for ( int i = 0; i< pseudoLabels.classIndex(); i++) { pseudoLabels.instance(0).setMissing(i); } Instances newDataSet = Instances.mergeInstances(pseudoLabels, features); newDataSet.setClassIndex(this.size); return newDataSet.instance(0); }
@Override public Instance transformInstance(Instance x) throws Exception{ Instances tmpInst = new Instances(x.dataset()); tmpInst.delete(); tmpInst.add(x); Instances features = this.extractPart(tmpInst, false); Instances pseudoLabels = new Instances(this.compressedMatrix); Instance tmpin = pseudoLabels.instance(0); pseudoLabels.delete(); pseudoLabels.add(tmpin); for ( int i = 0; i< pseudoLabels.classIndex(); i++) { pseudoLabels.instance(0).setMissing(i); } Instances newDataSet = Instances.mergeInstances(pseudoLabels, features); newDataSet.setClassIndex(this.size); return newDataSet.instance(0); }
@Override public Instance transformInstance(Instance x) throws Exception{ Instances tmpInst = new Instances(x.dataset()); tmpInst.delete(); tmpInst.add(x); Instances features = this.extractPart(tmpInst, false); Instances pseudoLabels = new Instances(this.compressedTemplateInst); Instance tmpin = pseudoLabels.instance(0); pseudoLabels.delete(); pseudoLabels.add(tmpin); for ( int i = 0; i< pseudoLabels.classIndex(); i++) { pseudoLabels.instance(0).setMissing(i); } Instances newDataSet = Instances.mergeInstances(pseudoLabels, features); newDataSet.setClassIndex(pseudoLabels.numAttributes()); return newDataSet.instance(0); }
@Override public Instance transformInstance(Instance x) throws Exception{ Instances tmpInst = new Instances(x.dataset()); tmpInst.delete(); tmpInst.add(x); Instances features = this.extractPart(tmpInst, false); Instances pseudoLabels = new Instances(this.compressedTemplateInst); Instance tmpin = pseudoLabels.instance(0); pseudoLabels.delete(); pseudoLabels.add(tmpin); for ( int i = 0; i< pseudoLabels.classIndex(); i++) { pseudoLabels.instance(0).setMissing(i); } Instances newDataSet = Instances.mergeInstances(pseudoLabels, features); newDataSet.setClassIndex(pseudoLabels.numAttributes()); return newDataSet.instance(0); }
irisData.firstInstance().setMissing(0); // set one value to missing Instances irisSummaryHeader = getIrisSummaryHeader();