in community/mahout-mr/mr-examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java [147:276]
private static boolean parseArgs(String[] args) {
DefaultOptionBuilder builder = new DefaultOptionBuilder();
Option help = builder.withLongName("help").withDescription("print this list").create();
Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();
Option scores = builder.withLongName("scores").withDescription("output score diagnostics during training").create();
ArgumentBuilder argumentBuilder = new ArgumentBuilder();
Option inputFile = builder.withLongName("input")
.withRequired(true)
.withArgument(argumentBuilder.withName("input").withMaximum(1).create())
.withDescription("where to get training data")
.create();
Option outputFile = builder.withLongName("output")
.withRequired(true)
.withArgument(argumentBuilder.withName("output").withMaximum(1).create())
.withDescription("where to get training data")
.create();
Option predictors = builder.withLongName("predictors")
.withRequired(true)
.withArgument(argumentBuilder.withName("p").create())
.withDescription("a list of predictor variables")
.create();
Option types = builder.withLongName("types")
.withRequired(true)
.withArgument(argumentBuilder.withName("t").create())
.withDescription("a list of predictor variable types (numeric, word, or text)")
.create();
Option target = builder.withLongName("target")
.withRequired(true)
.withArgument(argumentBuilder.withName("target").withMaximum(1).create())
.withDescription("the name of the target variable")
.create();
Option features = builder.withLongName("features")
.withArgument(
argumentBuilder.withName("numFeatures")
.withDefault("1000")
.withMaximum(1).create())
.withDescription("the number of internal hashed features to use")
.create();
Option passes = builder.withLongName("passes")
.withArgument(
argumentBuilder.withName("passes")
.withDefault("2")
.withMaximum(1).create())
.withDescription("the number of times to pass over the input data")
.create();
Option lambda = builder.withLongName("lambda")
.withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create())
.withDescription("the amount of coefficient decay to use")
.create();
Option rate = builder.withLongName("rate")
.withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create())
.withDescription("the learning rate")
.create();
Option noBias = builder.withLongName("noBias")
.withDescription("don't include a bias term")
.create();
Option targetCategories = builder.withLongName("categories")
.withRequired(true)
.withArgument(argumentBuilder.withName("number").withMaximum(1).create())
.withDescription("the number of target categories to be considered")
.create();
Group normalArgs = new GroupBuilder()
.withOption(help)
.withOption(quiet)
.withOption(inputFile)
.withOption(outputFile)
.withOption(target)
.withOption(targetCategories)
.withOption(predictors)
.withOption(types)
.withOption(passes)
.withOption(lambda)
.withOption(rate)
.withOption(noBias)
.withOption(features)
.create();
Parser parser = new Parser();
parser.setHelpOption(help);
parser.setHelpTrigger("--help");
parser.setGroup(normalArgs);
parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
CommandLine cmdLine = parser.parseAndHelp(args);
if (cmdLine == null) {
return false;
}
TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile);
TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile);
List<String> typeList = new ArrayList<>();
for (Object x : cmdLine.getValues(types)) {
typeList.add(x.toString());
}
List<String> predictorList = new ArrayList<>();
for (Object x : cmdLine.getValues(predictors)) {
predictorList.add(x.toString());
}
lmp = new LogisticModelParameters();
lmp.setTargetVariable(getStringArgument(cmdLine, target));
lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories));
lmp.setNumFeatures(getIntegerArgument(cmdLine, features));
lmp.setUseBias(!getBooleanArgument(cmdLine, noBias));
lmp.setTypeMap(predictorList, typeList);
lmp.setLambda(getDoubleArgument(cmdLine, lambda));
lmp.setLearningRate(getDoubleArgument(cmdLine, rate));
TrainLogistic.scores = getBooleanArgument(cmdLine, scores);
TrainLogistic.passes = getIntegerArgument(cmdLine, passes);
return true;
}