/** * Tries to classify an example. * * @param example the example to classify * @return true if it could be classified * @throws Exception if something goes wrong */ private boolean classifyExample(Instance example) throws Exception { double classValue = -1.0; for (Enumeration<RuleList> e = new WekaEnumeration<RuleList>(m_DecisionList); e .hasMoreElements() && classValue < 0.0;) { RuleList rl = e.nextElement(); classValue = rl.classifyInstance(example); } if (classValue >= 0.0) { example.setClassValue(classValue); return true; } else { return false; } }
/** * Tries to classify an example. * * @param example the example to classify * @return true if it could be classified * @throws Exception if something goes wrong */ private boolean classifyExample(Instance example) throws Exception { double classValue = -1.0; for (Enumeration<RuleList> e = new WekaEnumeration<RuleList>(m_DecisionList); e .hasMoreElements() && classValue < 0.0;) { RuleList rl = e.nextElement(); classValue = rl.classifyInstance(example); } if (classValue >= 0.0) { example.setClassValue(classValue); return true; } else { return false; } }
public Instance instanceToWeka(net.sf.javaml.core.Instance inst) { double[] values = new double[classSet ? inst.noAttributes() + 1 : inst.noAttributes()]; // System.arraycopy(i.values().t.toArray(), 0, values, 0, classSet ? // values.length - 1 : values.length); for (int i = 0; i < (classSet ? values.length - 1 : values.length); i++) { values[i] = inst.get(i); } // if (classSet) // values[values.length - 1] = inst.classValue(); Instance wI = null; if (inst instanceof net.sf.javaml.core.SparseInstance) wI = new SparseInstance(1, values); else wI = new Instance(1, values); wI.setDataset(wData); if (inst.classValue() != null) { wI.setClassValue(inst.classValue().toString()); } return wI; }
Instance tmpInstance = new SparseInstance(); tmpInstance.put(2, 1.0); tmpInstance.put(4, 2.2); tmpInstance.setClassValue("positive");
x_sl.setClassValue(comb); x_subsets[0] = x_sl; x_sl.setClassValue(d_subsets[i]); x_subsets[i] = x_sl;
@Override public void updateClassifier(Instance x) throws Exception { int L = x.classIndex(); for (int j = 0; j < L; j++) { if(x.value(j) > 0.0) { Instance x_j = convertInstance(x); x_j.setClassValue(j); ((UpdateableClassifier)m_Classifier).updateClassifier(x_j); } } }
@Override public void updateClassifier(Instance x) throws Exception { int L = x.classIndex(); for (int j = 0; j < L; j++) { if(x.value(j) > 0.0) { Instance x_j = convertInstance(x); x_j.setClassValue(j); ((UpdateableClassifier)m_Classifier).updateClassifier(x_j); } } }
@Override public void updateClassifier(Instance x) throws Exception { int L = x.classIndex(); for (int j = 0; j < L; j++) { if(x.value(j) > 0.0) { Instance x_j = convertInstance(x); x_j.setClassValue(j); ((UpdateableClassifier)m_Classifier).updateClassifier(x_j); } } }
x_subsets[0].setClassValue(y.toString()); // problem here! return x_subsets; for(int i = 1; i < d_subsets.length; i++) { x_subsets[i] = (Instance)(x_template).copy(); x_subsets[i].setClassValue(d_subsets[i].toString());
/** * Replace the class values of the instances from the current iteration * with residuals after predicting the given constant. * * @param data the instances to predict * @param c the constant to use * @return a new set of instances with class values replaced by residuals * @throws Exception if something goes wrong */ private Instances residualReplace(Instances data, double c) throws Exception { Instances newInst = new Instances(data); for (int i = 0; i < newInst.numInstances(); i++) { newInst.instance(i).setClassValue(newInst.instance(i).classValue() - c); } return newInst; }
/** * Replace the class values of the instances from the current iteration * with residuals after predicting the given constant. * * @param data the instances to predict * @param c the constant to use * @return a new set of instances with class values replaced by residuals * @throws Exception if something goes wrong */ private Instances residualReplace(Instances data, double c) throws Exception { Instances newInst = new Instances(data); for (int i = 0; i < newInst.numInstances(); i++) { newInst.instance(i).setClassValue(newInst.instance(i).classValue() - c); } return newInst; }
protected Instances convert(Instances D, int j, int k) { int L = D.classIndex(); D = new Instances(D); D.insertAttributeAt(classAttribute,0); D.setClassIndex(0); for(int i = 0; i < D.numInstances(); i++) { String c = (String)((int)Math.round(D.instance(i).value(j+1))+""+(int)Math.round(D.instance(i).value(k+1))); D.instance(i).setClassValue(c); } for (int i = 0; i < L; i++) D.deleteAttributeAt(1); m_InstancesTemplate = new Instances(D,0); return D; }
protected Instances convert(Instances D, int j, int k) { int L = D.classIndex(); D = new Instances(D); D.insertAttributeAt(classAttribute,0); D.setClassIndex(0); for(int i = 0; i < D.numInstances(); i++) { String c = (String)((int)Math.round(D.instance(i).value(j+1))+""+(int)Math.round(D.instance(i).value(k+1))); D.instance(i).setClassValue(c); } for (int i = 0; i < L; i++) D.deleteAttributeAt(1); m_InstancesTemplate = new Instances(D,0); return D; }
protected Instances convert(Instances D, int j, int k) { int L = D.classIndex(); D = new Instances(D); D.insertAttributeAt(classAttribute,0); D.setClassIndex(0); for(int i = 0; i < D.numInstances(); i++) { String c = (String)((int)Math.round(D.instance(i).value(j+1))+""+(int)Math.round(D.instance(i).value(k+1))); D.instance(i).setClassValue(c); } for (int i = 0; i < L; i++) D.deleteAttributeAt(1); m_InstancesTemplate = new Instances(D,0); return D; }
Instance datum = (Instance) instance.copy(); if (!datum.isMissing(m_ClassAttribute)) { datum.setClassValue(m_Converter[(int) datum.classValue()]);
/** * Replace the class values of the instances from the current iteration * with residuals after predicting with the supplied classifier. * * @param data the instances to predict * @param c the classifier to use * @return a new set of instances with class values replaced by residuals * @throws Exception if something goes wrong */ private Instances residualReplace(Instances data, Classifier c) throws Exception { Instances newInst = new Instances(data); for (int i = 0; i < newInst.numInstances(); i++) { double pred = c.classifyInstance(newInst.instance(i)); if (Utils.isMissingValue(pred)) { throw new UnassignedClassException("AdditiveRegression: base learner predicted missing value."); } newInst.instance(i).setClassValue(newInst.instance(i).classValue() - (pred * getShrinkage())); } return newInst; }
/** * Replace the class values of the instances from the current iteration * with residuals after predicting with the supplied classifier. * * @param data the instances to predict * @param c the classifier to use * @return a new set of instances with class values replaced by residuals * @throws Exception if something goes wrong */ private Instances residualReplace(Instances data, Classifier c) throws Exception { Instances newInst = new Instances(data); for (int i = 0; i < newInst.numInstances(); i++) { double pred = c.classifyInstance(newInst.instance(i)); if (Utils.isMissingValue(pred)) { throw new UnassignedClassException("AdditiveRegression: base learner predicted missing value."); } newInst.instance(i).setClassValue(newInst.instance(i).classValue() - (pred * getShrinkage())); } return newInst; }
newInstance.setClassValue( instance.classValue() ); return newInstance;
/** * Called by JUnit before each test method. This implementation creates * the default filter to test and loads a test set of Instances. * * @throws Exception if an error occurs reading the example instances. */ protected void setUp() throws Exception { super.setUp(); TestInstances test = new TestInstances(); test.setNumNominal(2); test.setClassType(Attribute.NOMINAL); test.setNumInstances(400); m_Instances = test.generate(); for (int i = 0; i < m_Instances.numInstances(); i++) { m_Instances.instance(i).setClassValue(((int) m_Instances.instance(i).value(0) % m_Instances.numClasses())); } }
private void buildModel(ZooModel model) throws Exception { // CLF Dl4jMlpClassifier clf = new Dl4jMlpClassifier(); clf.setSeed(1); // Data Instances data = DatasetLoader.loadMiniMnistMeta(); ArrayList<Attribute> atts = new ArrayList<>(); for (int i = 0; i < data.numAttributes(); i++) { atts.add(data.attribute(i)); } Instances shrinkedData = new Instances("shrinked", atts, 10); shrinkedData.setClassIndex(1); for (int i = 0; i < 10; i++) { Instance inst = data.get(i); inst.setClassValue(i % 10); inst.setDataset(shrinkedData); shrinkedData.add(inst); } ImageInstanceIterator iterator = DatasetLoader.loadMiniMnistImageIterator(); iterator.setTrainBatchSize(10); clf.setInstanceIterator(iterator); clf.setZooModel(model); clf.setNumEpochs(1); final EpochListener epochListener = new EpochListener(); epochListener.setN(1); clf.setIterationListener(epochListener); clf.setEarlyStopping(new EarlyStopping(5, 0)); clf.buildClassifier(shrinkedData); }