/** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { Vector<String> options = new Vector<String>(); options.add("-S"); options.add("" + getShrinkage()); if (getMinimizeAbsoluteError()) { options.add("-A"); } Collections.addAll(options, super.getOptions()); return options.toArray(new String[0]); }
/** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { Vector<String> options = new Vector<String>(); options.add("-S"); options.add("" + getShrinkage()); if (getMinimizeAbsoluteError()) { options.add("-A"); } if (getResume()) { options.add("-resume"); } Collections.addAll(options, super.getOptions()); return options.toArray(new String[0]); }
/** * Classify an instance. * * @param inst the instance to predict * @return a prediction for the instance * @throws Exception if an error occurs */ public double classifyInstance(Instance inst) throws Exception { double prediction = m_InitialPrediction; // default model? if (!m_SuitableData) { return prediction; } for (Classifier classifier : m_Classifiers) { double toAdd = classifier.classifyInstance(inst); if (Utils.isMissingValue(toAdd)) { throw new UnassignedClassException("AdditiveRegression: base learner predicted missing value."); } prediction += (toAdd * getShrinkage()); } return prediction; }
/** * Classify an instance. * * @param inst the instance to predict * @return a prediction for the instance * @throws Exception if an error occurs */ public double classifyInstance(Instance inst) throws Exception { double prediction = m_InitialPrediction; // default model? if (!m_SuitableData) { return prediction; } for (Classifier classifier : m_Classifiers) { double toAdd = classifier.classifyInstance(inst); if (Utils.isMissingValue(toAdd)) { throw new UnassignedClassException("AdditiveRegression: base learner predicted missing value."); } prediction += (toAdd * getShrinkage()); } return prediction; }
/** * 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; }