....previous code omitted, can be seen in the question... Instance inst = new Instance(1.0,values); dataset.add(inst); inst.setDataset(dataset); ....following code omitted, can be seen in the question...
public static Instance linkTransformation(Instance x, int excl[], Instances _template) { // copy Instance copy = (Instance)x.copy(); copy.setDataset(null); // delete attributes we don't need for(int i = excl.length-1; i >= 0; i--) { copy.deleteAttributeAt(excl[i]); } //set template copy.setDataset(_template); return copy; }
/** * Convert a multi-label instance into a multi-class instance, according to a template. */ public static Instance convertInstance(Instance x, int L, Instances template) { Instance x_ = (Instance) x.copy(); x_.setDataset(null); for (int i = 0; i < L; i++) x_.deleteAttributeAt(0); x_.insertAttributeAt(0); x_.setDataset(template); return x_; }
@Override public Instance convertInstance(Instance x, int L) { Instance x_sl = (Instance) x.copy(); x_sl.setDataset(null); for (int i = 0; i < L; i++) x_sl.deleteAttributeAt(0); x_sl.insertAttributeAt(0); x_sl.setDataset(m_InstancesTemplate); return x_sl; }
public Instance convertInstance(Instance TestInstance, int C) { Instance FilteredInstance = (Instance) TestInstance.copy(); FilteredInstance.setDataset(null); for (int i = 0; i < C; i++) FilteredInstance.deleteAttributeAt(0); FilteredInstance.insertAttributeAt(0); FilteredInstance.setDataset(m_InstancesTemplate); return FilteredInstance; }
/** * Convert a multi-label instance into a multi-class instance, according to a template. */ public static Instance convertInstance(Instance x, int L, Instances template) { Instance x_ = (Instance) x.copy(); x_.setDataset(null); for (int i = 0; i < L; i++) x_.deleteAttributeAt(0); x_.insertAttributeAt(0); x_.setDataset(template); return x_; }
public static final Instance setTemplate(Instance x, Instances instancesTemplate) { int L = x.classIndex(); int L_t = instancesTemplate.classIndex(); x = (Instance)x.copy(); x.setDataset(null); for (int i = L_t; i < L; i++) x.deleteAttributeAt(0); x.setDataset(instancesTemplate); return x; }
public static final Instance setTemplate(Instance x, Instances instancesTemplate) { int L = x.classIndex(); int L_t = instancesTemplate.classIndex(); x = (Instance)x.copy(); x.setDataset(null); for (int i = L_t; i < L; i++) x.deleteAttributeAt(0); x.setDataset(instancesTemplate); return x; }
public static final Instance setTemplate(Instance x, Instances instancesTemplate) { int L = x.classIndex(); int L_t = instancesTemplate.classIndex(); x = (Instance)x.copy(); x.setDataset(null); for (int i = L_t; i < L; i++) x.deleteAttributeAt(0); x.setDataset(instancesTemplate); return x; }
protected MultiLabelOutput makePredictionInternal(Instance instance) throws Exception { //delete labels instance = RemoveAllLabels.transformInstance(instance, labelIndices); instance.setDataset(null); instance.insertAttributeAt(instance.numAttributes()); instance.setDataset(header); double[] distribution = baseClassifier.distributionForInstance(instance); MultiLabelOutput mlo = new MultiLabelOutput(MultiLabelOutput.ranksFromValues(distribution)); return mlo; } }
@Override public double[] distributionForInstance(Instance TestInstance) throws Exception { int c = TestInstance.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(c == 1) return new double[]{1.0}; Instance mlInstance = convertInstance(TestInstance,c); mlInstance.setDataset(m_InstancesTemplate); //Get a classification return convertDistribution(m_Classifier.distributionForInstance(mlInstance),c); }
// Create empty instance with three attribute values Instance inst = new DenseInstance(3); // Set instance's values for the attributes "length", "weight", and "position" inst.setValue(length, 5.3); inst.setValue(weight, 300); inst.setValue(position, "first"); // Set instance's dataset to be the dataset "race" inst.setDataset(race);
@Override public double[] distributionForInstance(Instance instance) throws Exception { int L = instance.classIndex(); Instance x = F.meka2mulan((Instance)instance.copy(),L); x.setDataset(m_InstancesTemplate); double y[] = m_MULAN.makePrediction(x).getConfidences(); return y; }
@Override public double[] distributionForInstance(Instance mlInstance) throws Exception { int c = mlInstance.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(c == 1) return new double[]{1.0}; Instance slInstance = convertInstance(mlInstance,c); slInstance.setDataset(m_InstancesTemplate); //Get a classification double result[] = new double[slInstance.numClasses()]; result[(int)m_Classifier.classifyInstance(slInstance)] = 1.0; return convertDistribution(result,c); }
@Override public double[] distributionForInstance(Instance instance) throws Exception { int L = instance.classIndex(); Instance x = F.meka2mulan((Instance)instance.copy(),L); x.setDataset(m_InstancesTemplate); double y[] = m_MULAN.makePrediction(x).getConfidences(); return y; }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(L == 1) return new double[]{1.0}; Instance x_ = PSUtils.convertInstance(x,L,m_InstancesTemplate); //convertInstance(x,L); x_.setDataset(m_InstancesTemplate); //Get a classification double y[] = new double[x_.numClasses()]; y[(int)m_Classifier.classifyInstance(x_)] = 1.0; return PSUtils.convertDistribution(y,L,m_InstancesTemplate); }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(L == 1) return new double[]{1.0}; Instance x_ = PSUtils.convertInstance(x,L,m_InstancesTemplate); //convertInstance(x,L); x_.setDataset(m_InstancesTemplate); //Get a classification double y[] = new double[x_.numClasses()]; y[(int)m_Classifier.classifyInstance(x_)] = 1.0; return PSUtils.convertDistribution(y,L,m_InstancesTemplate); }
private Instance createInstance(Instances data, FeatureDefinition fd, FeatureVector fv) { // relevant features + one target Instance currInst = new DenseInstance(data.numAttributes()); currInst.setDataset(data); // read only relevant features for (String attName : this.featureNames) { int featNr = fd.getFeatureIndex(attName); String value = fv.getFeatureAsString(featNr, fd); currInst.setValue(data.attribute(attName), value); } return currInst; }
@Override public double[] distributionForInstance(Instance xy) throws Exception { int L = xy.classIndex(); double z[] = dbm.prob_z(MLUtils.getxfromInstance(xy)); Instance zy = (Instance)m_InstancesTemplate.firstInstance().copy(); MLUtils.setValues(zy,z,L); zy.setDataset(m_InstancesTemplate); return m_Classifier.distributionForInstance(zy); }
@Override public double[] distributionForInstance(Instance xy) throws Exception { int L = xy.classIndex(); double z[] = dbm.prob_z(MLUtils.getxfromInstance(xy)); Instance zy = (Instance)m_InstancesTemplate.firstInstance().copy(); MLUtils.setValues(zy,z,L); zy.setDataset(m_InstancesTemplate); return m_Classifier.distributionForInstance(zy); }