📄 simplelogistic.java
字号:
} setUseAIC(Utils.getFlag('A', options)); Utils.checkForRemainingOptions(options); } /** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { String[] options = new String[11]; int current = 0; options[current++] = "-I"; options[current++] = ""+getNumBoostingIterations(); if (!getUseCrossValidation()) { options[current++] = "-S"; } if (getErrorOnProbabilities()) { options[current++] = "-P"; } options[current++] = "-M"; options[current++] = ""+getMaxBoostingIterations(); options[current++] = "-H"; options[current++] = ""+getHeuristicStop(); options[current++] = "-W"; options[current++] = ""+getWeightTrimBeta(); if (getUseAIC()) { options[current++] = "-A"; } while (current < options.length) { options[current++] = ""; } return options; } /** * Get the value of numBoostingIterations. * * @return the number of boosting iterations */ public int getNumBoostingIterations(){ return m_numBoostingIterations; } /** * Get the value of useCrossValidation. * * @return true if cross-validation is used */ public boolean getUseCrossValidation(){ return m_useCrossValidation; } /** * Get the value of errorOnProbabilities. * * @return If true, use minimize error on probabilities instead of * misclassification error */ public boolean getErrorOnProbabilities(){ return m_errorOnProbabilities; } /** * Get the value of maxBoostingIterations. * * @return the maximum number of boosting iterations */ public int getMaxBoostingIterations(){ return m_maxBoostingIterations; } /** * Get the value of heuristicStop. * * @return the value of heuristicStop */ public int getHeuristicStop(){ return m_heuristicStop; } /** * Get the value of weightTrimBeta. */ public double getWeightTrimBeta(){ return m_weightTrimBeta; } /** * Get the value of useAIC. * * @return Value of useAIC. */ public boolean getUseAIC(){ return m_useAIC; } /** * Set the value of numBoostingIterations. * * @param n the number of boosting iterations */ public void setNumBoostingIterations(int n){ m_numBoostingIterations = n; } /** * Set the value of useCrossValidation. * * @param l whether to use cross-validation */ public void setUseCrossValidation(boolean l){ m_useCrossValidation = l; } /** * Set the value of errorOnProbabilities. * * @param l If true, use minimize error on probabilities instead of * misclassification error */ public void setErrorOnProbabilities(boolean l){ m_errorOnProbabilities = l; } /** * Set the value of maxBoostingIterations. * * @param n the maximum number of boosting iterations */ public void setMaxBoostingIterations(int n){ m_maxBoostingIterations = n; } /** * Set the value of heuristicStop. * * @param n the value of heuristicStop */ public void setHeuristicStop(int n){ if (n == 0) m_heuristicStop = m_maxBoostingIterations; else m_heuristicStop = n; } /** * Set the value of weightTrimBeta. */ public void setWeightTrimBeta(double n){ m_weightTrimBeta = n; } /** * Set the value of useAIC. * * @param c Value to assign to useAIC. */ public void setUseAIC(boolean c){ m_useAIC = c; } /** * Get the number of LogitBoost iterations performed (= the number of * regression functions fit by LogitBoost). * * @return the number of LogitBoost iterations performed */ public int getNumRegressions(){ return m_boostedModel.getNumRegressions(); } /** * Returns a description of the logistic model (attributes/coefficients). * * @return the model as string */ public String toString(){ if (m_boostedModel == null) return "No model built"; return "SimpleLogistic:\n" + m_boostedModel.toString(); } /** * Returns the fraction of all attributes in the data that are used in the * logistic model (in percent). An attribute is used in the model if it is * used in any of the models for the different classes. * * @return percentage of attributes used in the model */ public double measureAttributesUsed(){ return m_boostedModel.percentAttributesUsed(); } /** * Returns an enumeration of the additional measure names * @return an enumeration of the measure names */ public Enumeration enumerateMeasures() { Vector newVector = new Vector(3); newVector.addElement("measureAttributesUsed"); newVector.addElement("measureNumIterations"); return newVector.elements(); } /** * Returns the value of the named measure * @param additionalMeasureName the name of the measure to query for its value * @return the value of the named measure * @throws IllegalArgumentException if the named measure is not supported */ public double getMeasure(String additionalMeasureName) { if (additionalMeasureName.compareToIgnoreCase("measureAttributesUsed") == 0) { return measureAttributesUsed(); } else if(additionalMeasureName.compareToIgnoreCase("measureNumIterations") == 0){ return getNumRegressions(); } else { throw new IllegalArgumentException(additionalMeasureName + " not supported (SimpleLogistic)"); } } /** * Returns a string describing classifier * @return a description suitable for * displaying in the explorer/experimenter gui */ public String globalInfo() { return "Classifier for building linear logistic regression models. LogitBoost with simple regression " +"functions as base learners is used for fitting the logistic models. The optimal number of LogitBoost " +"iterations to perform is cross-validated, which leads to automatic attribute selection. " +"For more information see:\n" + getTechnicalInformation().toString(); } /** * Returns an instance of a TechnicalInformation object, containing * detailed information about the technical background of this class, * e.g., paper reference or book this class is based on. * * @return the technical information about this class */ public TechnicalInformation getTechnicalInformation() { TechnicalInformation result; TechnicalInformation additional; result = new TechnicalInformation(Type.ARTICLE); result.setValue(Field.AUTHOR, "Niels Landwehr and Mark Hall and Eibe Frank"); result.setValue(Field.TITLE, "Logistic Model Trees"); result.setValue(Field.BOOKTITLE, "Machine Learning"); result.setValue(Field.YEAR, "2005"); result.setValue(Field.VOLUME, "95"); result.setValue(Field.PAGES, "161-205"); result.setValue(Field.NUMBER, "1-2"); additional = result.add(Type.INPROCEEDINGS); additional.setValue(Field.AUTHOR, "Marc Sumner and Eibe Frank and Mark Hall"); additional.setValue(Field.TITLE, "Speeding up Logistic Model Tree Induction"); additional.setValue(Field.BOOKTITLE, "9th European Conference on Principles and Practice of Knowledge Discovery in Databases"); additional.setValue(Field.YEAR, "2005"); additional.setValue(Field.PAGES, "675-683"); additional.setValue(Field.PUBLISHER, "Springer"); return result; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String numBoostingIterationsTipText() { return "Set fixed number of iterations for LogitBoost. If >= 0, this sets the number of LogitBoost iterations " +"to perform. If < 0, the number is cross-validated or a stopping criterion on the training set is used " +"(depending on the value of useCrossValidation)."; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String useCrossValidationTipText() { return "Sets whether the number of LogitBoost iterations is to be cross-validated or the stopping criterion " +"on the training set should be used. If not set (and no fixed number of iterations was given), " +"the number of LogitBoost iterations is used that minimizes the error on the training set " +"(misclassification error or error on probabilities depending on errorOnProbabilities)."; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String errorOnProbabilitiesTipText() { return "Use error on the probabilties as error measure when determining the best number of LogitBoost iterations. " +"If set, the number of LogitBoost iterations is chosen that minimizes the root mean squared error " +"(either on the training set or in the cross-validation, depending on useCrossValidation)."; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String maxBoostingIterationsTipText() { return "Sets the maximum number of iterations for LogitBoost. Default value is 500, for very small/large " +"datasets a lower/higher value might be preferable."; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String heuristicStopTipText() { return "If heuristicStop > 0, the heuristic for greedy stopping while cross-validating the number of " +"LogitBoost iterations is enabled. This means LogitBoost is stopped if no new error minimum " +"has been reached in the last heuristicStop iterations. It is recommended to use this heuristic, " +"it gives a large speed-up especially on small datasets. The default value is 50."; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String weightTrimBetaTipText() { return "Set the beta value used for weight trimming in LogitBoost. " +"Only instances carrying (1 - beta)% of the weight from previous iteration " +"are used in the next iteration. Set to 0 for no weight trimming. " +"The default value is 0."; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String useAICTipText() { return "The AIC is used to determine when to stop LogitBoost iterations " +"(instead of cross-validation or training error)."; } /** * Main method for testing this class * * @param argv commandline options */ public static void main(String[] argv) { try { System.out.println(Evaluation.evaluateModel(new SimpleLogistic(), argv)); } catch (Exception e) { e.printStackTrace(); System.err.println(e.getMessage()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -