List of usage examples for weka.core Utils partitionOptions
public static String[] partitionOptions(String[] options)
From source file:WrapperSubset.java
License:Open Source License
/** * Parses a given list of options./* w w w.j a va2 s. c o m*/ * <p/> * * <!-- options-start --> Valid options are: * <p/> * * <pre> * -B <base learner> * class name of base learner to use for accuracy estimation. * Place any classifier options LAST on the command line * following a "--". eg.: * -B weka.classifiers.bayes.NaiveBayes ... -- -K * (default: weka.classifiers.rules.ZeroR) * </pre> * * <pre> * -F <num> * number of cross validation folds to use for estimating accuracy. * (default=5) * </pre> * * <pre> * -R <seed> * Seed for cross validation accuracy testimation. * (default = 1) * </pre> * * <pre> * -T <num> * threshold by which to execute another cross validation * (standard deviation---expressed as a percentage of the mean). * (default: 0.01 (1%)) * </pre> * * <pre> * -E <acc | rmse | mae | f-meas | auc | auprc> * Performance evaluation measure to use for selecting attributes. * (Default = accuracy for discrete class and rmse for numeric class) * </pre> * * <pre> * -IRclass <label | index> * Optional class value (label or 1-based index) to use in conjunction with * IR statistics (f-meas, auc or auprc). Omitting this option will use * the class-weighted average. * </pre> * * <pre> * Options specific to scheme weka.classifiers.rules.ZeroR: * </pre> * * <pre> * -D * If set, classifier is run in debug mode and * may output additional info to the console * </pre> * * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ @Override public void setOptions(String[] options) throws Exception { String optionString; resetOptions(); optionString = Utils.getOption('B', options); if (optionString.length() == 0) { optionString = ZeroR.class.getName(); } setClassifier(AbstractClassifier.forName(optionString, Utils.partitionOptions(options))); optionString = Utils.getOption('F', options); if (optionString.length() != 0) { setFolds(Integer.parseInt(optionString)); } optionString = Utils.getOption('R', options); if (optionString.length() != 0) { setSeed(Integer.parseInt(optionString)); } // optionString = Utils.getOption('S',options); // if (optionString.length() != 0) // { // seed = Integer.parseInt(optionString); // } optionString = Utils.getOption('T', options); if (optionString.length() != 0) { Double temp; temp = Double.valueOf(optionString); setThreshold(temp.doubleValue()); } optionString = Utils.getOption('E', options); if (optionString.length() != 0) { if (optionString.equals("acc")) { setEvaluationMeasure(new SelectedTag(EVAL_ACCURACY, TAGS_EVALUATION)); } else if (optionString.equals("rmse")) { setEvaluationMeasure(new SelectedTag(EVAL_RMSE, TAGS_EVALUATION)); } else if (optionString.equals("mae")) { setEvaluationMeasure(new SelectedTag(EVAL_MAE, TAGS_EVALUATION)); } else if (optionString.equals("f-meas")) { setEvaluationMeasure(new SelectedTag(EVAL_FMEASURE, TAGS_EVALUATION)); } else if (optionString.equals("auc")) { setEvaluationMeasure(new SelectedTag(EVAL_AUC, TAGS_EVALUATION)); } else if (optionString.equals("auprc")) { setEvaluationMeasure(new SelectedTag(EVAL_AUPRC, TAGS_EVALUATION)); } else { throw new IllegalArgumentException("Invalid evaluation measure"); } } optionString = Utils.getOption("IRClass", options); if (optionString.length() > 0) { setIRClassValue(optionString); } }
From source file:com.spread.experiment.tempuntilofficialrelease.ClassificationViaClustering108.java
License:Open Source License
/** * Parses the options for this object.//from www .j av a2 s . c o m * <p/> * * <!-- options-start --> Valid options are: * <p/> * * <pre> * -output-debug-info * If set, classifier is run in debug mode and * may output additional info to the console * </pre> * * <pre> * -W <clusterer> * Full name of clusterer. * (default: weka.clusterers.SimpleKMeans) * </pre> * * <pre> * -label-all-clusters * If set, all clusters are labeled probabilistically instead of just those ones that best fit a class * </pre> * * <pre> * Options specific to clusterer weka.clusterers.SimpleKMeans: * </pre> * * <pre> * -N <num> * number of clusters. * (default 2). * </pre> * * <pre> * -V * Display std. deviations for centroids. * </pre> * * <pre> * -M * Replace missing values with mean/mode. * </pre> * * <pre> * -S <num> * Random number seed. * (default 10) * </pre> * * <!-- options-end --> * * @param options the options to use * @throws Exception if setting of options fails */ @Override public void setOptions(String[] options) throws Exception { setLabelAllClusters(Utils.getFlag("label-all-clusters", options)); String tmpStr = Utils.getOption('W', options); if (tmpStr.length() > 0) { setClusterer(AbstractClusterer.forName(tmpStr, null)); setClusterer(AbstractClusterer.forName(tmpStr, Utils.partitionOptions(options))); } else { setClusterer(AbstractClusterer.forName(defaultClustererString(), null)); setClusterer(AbstractClusterer.forName(defaultClustererString(), Utils.partitionOptions(options))); } super.setOptions(options); Utils.checkForRemainingOptions(options); }
From source file:milk.classifiers.MIBoost.java
License:Open Source License
/** * Parses a given list of options. Valid options are:<p> *//from w w w . ja v a 2s. c o m * -D <br> * Turn on debugging output.<p> * * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setDebug(Utils.getFlag('D', options)); String bin = Utils.getOption('B', options); if (bin.length() != 0) { setDiscretizeBin(Integer.parseInt(bin)); } else { setDiscretizeBin(0); } String boostIterations = Utils.getOption('R', options); if (boostIterations.length() != 0) { setMaxIterations(Integer.parseInt(boostIterations)); } else { setMaxIterations(10); } String classifierName = Utils.getOption('W', options); if (classifierName.length() != 0) m_Classifier = Classifier.forName(classifierName, Utils.partitionOptions(options)); else { //throw new Exception("A classifier must be specified with" // + " the -W option."); //m_Classifier = new weka.classifiers.trees.DecisionStump(); } }
From source file:milk.classifiers.MIWrapper.java
License:Open Source License
/** * Parses a given list of options. Valid options are:<p> *//w w w. ja v a2 s. c om * -D <br> * Turn on debugging output.<p> * * -W classname <br> * Specify the full class name of a classifier as the basis (required).<p> * * -P method_index <br> * Set which method to use in testing: 1.arithmatic average; 2.geometric average. (default: 1)<p> * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setDebug(Utils.getFlag('D', options)); String methodString = Utils.getOption('P', options); if (methodString.length() != 0) { setMethod(Integer.parseInt(methodString)); } else { setMethod(1); } String classifierName = Utils.getOption('W', options); if (classifierName.length() == 0) { throw new Exception("A classifier must be specified with" + " the -W option."); } setClassifier(Classifier.forName(classifierName, Utils.partitionOptions(options))); }
From source file:milk.classifiers.SimpleMI.java
License:Open Source License
/** * Parses a given list of options. Valid options are:<p> */*from w ww . j av a 2 s .c o m*/ * -M method_index <br> * Set which method to use in transformation: 1.arithmatic average; 2.geometric centor * of a bag (default: 1)<p> * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String methodString = Utils.getOption('M', options); if (methodString.length() != 0) { setTransformMethod(Integer.parseInt(methodString)); } else { setTransformMethod(1); } String classifierName = Utils.getOption('W', options); if (classifierName.length() == 0) { throw new Exception("A classifier must be specified with" + " the -W option."); } setClassifier(Classifier.forName(classifierName, Utils.partitionOptions(options))); }
From source file:milk.experiment.MIClassifierSplitEvaluator.java
License:Open Source License
/** * Parses a given list of options. Valid options are:<p> *// w ww . j a va 2 s . c o m * -W classname <br> * Specify the full class name of the classifier to evaluate. <p> * * -C class index <br> * The index of the class for which IR statistics are to * be output. (default 1) <p> * * All option after -- will be passed to the classifier. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String cName = Utils.getOption('W', options); if (cName.length() == 0) { throw new Exception("A classifier must be specified with" + " the -W option."); } // Do it first without options, so if an exception is thrown during // the option setting, listOptions will contain options for the actual // Classifier. setClassifier(MIClassifier.forName(cName, null)); if (getClassifier() instanceof OptionHandler) { ((OptionHandler) getClassifier()).setOptions(Utils.partitionOptions(options)); updateOptions(); } String indexName = Utils.getOption('C', options); if (indexName.length() != 0) { m_IRclass = (new Integer(indexName)).intValue() - 1; } else { m_IRclass = 0; } }
From source file:milk.experiment.MICrossValidationResultProducer.java
License:Open Source License
/** * Parses a given list of options. Valid options are:<p> */*from w w w . j a v a2 s . co m*/ * -X num_folds <br> * The number of folds to use for the cross-validation. <p> * * -D <br> * Specify that raw split evaluator output is to be saved. <p> * * -O file/directory name <br> * Specify the file or directory to which raw split evaluator output * is to be saved. If a directory is specified, then each output string * is saved as an individual gzip file. If a file is specified, then * each output string is saved as an entry in a zip file. <p> * * -W classname <br> * Specify the full class name of the split evaluator. <p> * * All option after -- will be passed to the split evaluator. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setRawOutput(Utils.getFlag('D', options)); String fName = Utils.getOption('O', options); if (fName.length() != 0) { setOutputFile(new File(fName)); } String numFolds = Utils.getOption('X', options); if (numFolds.length() != 0) { setNumFolds(Integer.parseInt(numFolds)); } else { setNumFolds(10); } String seName = Utils.getOption('W', options); if (seName.length() == 0) { throw new Exception("A SplitEvaluator must be specified with" + " the -W option."); } // Do it first without options, so if an exception is thrown during // the option setting, listOptions will contain options for the actual // SE. setSplitEvaluator((MISplitEvaluator) Utils.forName(MISplitEvaluator.class, seName, null)); if (getSplitEvaluator() instanceof OptionHandler) { ((OptionHandler) getSplitEvaluator()).setOptions(Utils.partitionOptions(options)); } }
From source file:milk.experiment.MIExperiment.java
License:Open Source License
/** * Parses a given list of options. Valid options are:<p> */*from ww w . j a v a 2s .c o m*/ * -L num <br> * The lower run number to start the experiment from. * (default 1) <p> * * -U num <br> * The upper run number to end the experiment at (inclusive). * (default 10) <p> * * -T arff_file <br> * The dataset to run the experiment on. * (required, may be specified multiple times) <p> * * -P class_name <br> * The full class name of a ResultProducer (required). * eg: weka.experiment.RandomSplitResultProducer <p> * * -D "class_name" <br> * The full class name of a ResultListener followed by any options. * If options are supplied then full string must be enclosed in quotes. * (required). * eg: "weka.experiment.CSVResultListener -O outfile.csv" <p> * * All option after -- will be passed to the result producer. <p> * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String lowerString = Utils.getOption('L', options); if (lowerString.length() != 0) { setRunLower(Integer.parseInt(lowerString)); } else { setRunLower(1); } String upperString = Utils.getOption('U', options); if (upperString.length() != 0) { setRunUpper(Integer.parseInt(upperString)); } else { setRunUpper(10); } if (getRunLower() > getRunUpper()) { throw new Exception("Lower (" + getRunLower() + ") is greater than upper (" + getRunUpper() + ")"); } setNotes(Utils.getOption('N', options)); getDatasets().removeAllElements(); String dataName; do { dataName = Utils.getOption('T', options); if (dataName.length() != 0) { File dataset = new File(dataName); getDatasets().addElement(dataset); } } while (dataName.length() != 0); if (getDatasets().size() == 0) { throw new Exception("Required: -T <arff file name>"); } String rlName = Utils.getOption('D', options); if (rlName.length() == 0) { throw new Exception("Required: -D <ResultListener class name>"); } rlName = rlName.trim(); // split off any options int breakLoc = rlName.indexOf(' '); String clName = rlName; String rlOptionsString = ""; String[] rlOptions = null; if (breakLoc != -1) { clName = rlName.substring(0, breakLoc); rlOptionsString = rlName.substring(breakLoc).trim(); rlOptions = Utils.splitOptions(rlOptionsString); } setResultListener((MIResultListener) Utils.forName(MIResultListener.class, clName, rlOptions)); String rpName = Utils.getOption('P', options); if (rpName.length() == 0) { throw new Exception("Required: -P <ResultProducer class name>"); } // Do it first without options, so if an exception is thrown during // the option setting, listOptions will contain options for the actual // RP. //GHF -- nice idea, but it prevents you from using result producers that // have *required* parameters setResultProducer( (MIResultProducer) Utils.forName(MIResultProducer.class, rpName, Utils.partitionOptions(options))); //GHF //GHF if (getResultProducer() instanceof OptionHandler) { //GHF ((OptionHandler) getResultProducer()) //GHF .setOptions(Utils.partitionOptions(options)); //GHF } }
From source file:milk.experiment.MIRandomSplitResultProducer.java
License:Open Source License
/** * Parses a given list of options. Valid options are:<p> */* ww w . j av a 2 s .com*/ * -P num <br> * The percent of instances used for training. <p> * * -D <br> * Specify that raw split evaluator output is to be saved. <p> * * -R <br> * Do not randomize the dataset. <p> * * -O file/directory name <br> * Specify the file or directory to which raw split evaluator output * is to be saved. If a directory is specified, then each output string * is saved as an individual gzip file. If a file is specified, then * each output string is saved as an entry in a zip file. <p> * * -W classname <br> * Specify the full class name of the split evaluator. <p> * * All option after -- will be passed to the split evaluator. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setRawOutput(Utils.getFlag('D', options)); setRandomizeData(!Utils.getFlag('R', options)); String fName = Utils.getOption('O', options); if (fName.length() != 0) { setOutputFile(new File(fName)); } String trainPct = Utils.getOption('P', options); if (trainPct.length() != 0) { setTrainPercent((new Double(trainPct)).doubleValue()); } else { setTrainPercent(66); } String seName = Utils.getOption('W', options); if (seName.length() == 0) { throw new Exception("A SplitEvaluator must be specified with" + " the -W option."); } // Do it first without options, so if an exception is thrown during // the option setting, listOptions will contain options for the actual // SE. setSplitEvaluator((MISplitEvaluator) Utils.forName(MISplitEvaluator.class, seName, null)); if (getSplitEvaluator() instanceof OptionHandler) { ((OptionHandler) getSplitEvaluator()).setOptions(Utils.partitionOptions(options)); } }
From source file:sg.edu.nus.comp.nlp.ims.classifiers.CMultiClassesSVM.java
License:Open Source License
@Override public void setOptions(String[] p_Options) throws Exception { String iid = Utils.getOption('I', p_Options); if (iid != null) { this.m_IndexOfID = Integer.parseInt(iid); }/*w w w . j a v a 2 s . c o m*/ ((OptionHandler) this.m_Classifier).setOptions(Utils.partitionOptions(p_Options)); }