List of usage examples for weka.core SelectedTag SelectedTag
public SelectedTag(String tagText, Tag[] tags)
SelectedTag instance. From source file:MultiClassClassifier.java
License:Open Source License
/** * Parses a given list of options. <p/> * <!-- options-start -->/*from ww w . j a v a 2 s . c o m*/ * Valid options are: <p/> * * <pre> -M <num> * Sets the method to use. Valid values are 0 (1-against-all), * 1 (random codes), 2 (exhaustive code), and 3 (1-against-1). (default 0) * </pre> * * <pre> -R <num> * Sets the multiplier when using random codes. (default 2.0)</pre> * * <pre> -P * Use pairwise coupling (only has an effect for 1-against1)</pre> * * <pre> -S <num> * Random number seed. * (default 1)</pre> * * <pre> -D * If set, classifier is run in debug mode and * may output additional info to the console</pre> * * <pre> -W * Full name of base classifier. * (default: weka.classifiers.functions.Logistic)</pre> * * <pre> * Options specific to classifier weka.classifiers.functions.Logistic: * </pre> * * <pre> -D * Turn on debugging output.</pre> * * <pre> -R <ridge> * Set the ridge in the log-likelihood.</pre> * * <pre> -M <number> * Set the maximum number of iterations (default -1, until convergence).</pre> * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String errorString = Utils.getOption('M', options); if (errorString.length() != 0) { setMethod(new SelectedTag(Integer.parseInt(errorString), TAGS_METHOD)); } else { setMethod(new SelectedTag(METHOD_1_AGAINST_ALL, TAGS_METHOD)); } String rfactorString = Utils.getOption('R', options); if (rfactorString.length() != 0) { setRandomWidthFactor((new Double(rfactorString)).doubleValue()); } else { setRandomWidthFactor(2.0); } setUsePairwiseCoupling(Utils.getFlag('P', options)); super.setOptions(options); }
From source file:MultiClassClassifier.java
License:Open Source License
/** * Gets the method used. Will be one of METHOD_1_AGAINST_ALL, * METHOD_ERROR_RANDOM, METHOD_ERROR_EXHAUSTIVE, or METHOD_1_AGAINST_1. * * @return the current method./* w w w.j a va 2 s .c o m*/ */ public SelectedTag getMethod() { return new SelectedTag(m_Method, TAGS_METHOD); }
From source file:WrapperSubset.java
License:Open Source License
/** * Parses a given list of options./* w w w.jav a 2s . co 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:WrapperSubset.java
License:Open Source License
/** * Gets the currently set performance evaluation measure used for selecting * attributes for the decision table//from w w w .ja v a 2 s . c o m * * @return the performance evaluation measure */ public SelectedTag getEvaluationMeasure() { return new SelectedTag(m_evaluationMeasure, TAGS_EVALUATION); }
From source file:SMO.java
License:Open Source License
/** * Parses a given list of options. <p/> * <!-- options-start -->/*from w ww . j a v a 2 s . c om*/ * Valid options are: <p/> * * <pre> -D * If set, classifier is run in debug mode and * may output additional info to the console</pre> * * <pre> -no-checks * Turns off all checks - use with caution! * Turning them off assumes that data is purely numeric, doesn't * contain any missing values, and has a nominal class. Turning them * off also means that no header information will be stored if the * machine is linear. Finally, it also assumes that no instance has * a weight equal to 0. * (default: checks on)</pre> * * <pre> -C <double> * The complexity constant C. (default 1)</pre> * * <pre> -N * Whether to 0=normalize/1=standardize/2=neither. (default 0=normalize)</pre> * * <pre> -L <double> * The tolerance parameter. (default 1.0e-3)</pre> * * <pre> -P <double> * The epsilon for round-off error. (default 1.0e-12)</pre> * * <pre> -M * Fit logistic models to SVM outputs. </pre> * * <pre> -V <double> * The number of folds for the internal * cross-validation. (default -1, use training data)</pre> * * <pre> -W <double> * The random number seed. (default 1)</pre> * * <pre> -K <classname and parameters> * The Kernel to use. * (default: weka.classifiers.functions.supportVector.PolyKernel)</pre> * * <pre> * Options specific to kernel weka.classifiers.functions.supportVector.PolyKernel: * </pre> * * <pre> -D * Enables debugging output (if available) to be printed. * (default: off)</pre> * * <pre> -no-checks * Turns off all checks - use with caution! * (default: checks on)</pre> * * <pre> -C <num> * The size of the cache (a prime number), 0 for full cache and * -1 to turn it off. * (default: 250007)</pre> * * <pre> -E <num> * The Exponent to use. * (default: 1.0)</pre> * * <pre> -L * Use lower-order terms. * (default: no)</pre> * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String tmpStr; String[] tmpOptions; setChecksTurnedOff(Utils.getFlag("no-checks", options)); tmpStr = Utils.getOption('C', options); if (tmpStr.length() != 0) setC(Double.parseDouble(tmpStr)); else setC(1.0); tmpStr = Utils.getOption('L', options); if (tmpStr.length() != 0) setToleranceParameter(Double.parseDouble(tmpStr)); else setToleranceParameter(1.0e-3); tmpStr = Utils.getOption('P', options); if (tmpStr.length() != 0) setEpsilon(Double.parseDouble(tmpStr)); else setEpsilon(1.0e-12); tmpStr = Utils.getOption('N', options); if (tmpStr.length() != 0) setFilterType(new SelectedTag(Integer.parseInt(tmpStr), TAGS_FILTER)); else setFilterType(new SelectedTag(FILTER_NORMALIZE, TAGS_FILTER)); setBuildLogisticModels(Utils.getFlag('M', options)); tmpStr = Utils.getOption('V', options); if (tmpStr.length() != 0) setNumFolds(Integer.parseInt(tmpStr)); else setNumFolds(-1); tmpStr = Utils.getOption('W', options); if (tmpStr.length() != 0) setRandomSeed(Integer.parseInt(tmpStr)); else setRandomSeed(1); tmpStr = Utils.getOption('K', options); tmpOptions = Utils.splitOptions(tmpStr); if (tmpOptions.length != 0) { tmpStr = tmpOptions[0]; tmpOptions[0] = ""; setKernel(Kernel.forName(tmpStr, tmpOptions)); } super.setOptions(options); }
From source file:SMO.java
License:Open Source License
/** * Gets how the training data will be transformed. Will be one of * FILTER_NORMALIZE, FILTER_STANDARDIZE, FILTER_NONE. * * @return the filtering mode//ww w. j a va 2 s . c o m */ public SelectedTag getFilterType() { return new SelectedTag(m_filterType, TAGS_FILTER); }
From source file:MPCKMeans.java
License:Open Source License
/** Is metric learning performed? * @return is metric learning being done? *//*from ww w . j a v a 2 s . c o m*/ public SelectedTag getTrainable() { return new SelectedTag(m_Trainable, TAGS_TRAINING); }
From source file:MPCKMeans.java
License:Open Source License
/** * Parses a given list of options.// w w w . j a v a 2 s .c o m * @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 { if (Utils.getFlag('X', options)) { System.out.println("Setting seedable to: false"); setSeedable(false); } String optionString = Utils.getOption('T', options); if (optionString.length() != 0) { setTrainable(new SelectedTag(Integer.parseInt(optionString), TAGS_TRAINING)); System.out.println("Setting trainable to: " + Integer.parseInt(optionString)); } optionString = Utils.getOption('M', options); if (optionString.length() != 0) { String[] metricSpec = Utils.splitOptions(optionString); String metricName = metricSpec[0]; metricSpec[0] = ""; setMetric((LearnableMetric) Utils.forName(LearnableMetric.class, metricName, metricSpec)); System.out.println("Setting metric to: " + metricName); } optionString = Utils.getOption('L', options); if (optionString.length() != 0) { String[] learnerSpec = Utils.splitOptions(optionString); String learnerName = learnerSpec[0]; learnerSpec[0] = ""; setMetricLearner( (MPCKMeansMetricLearner) Utils.forName(MPCKMeansMetricLearner.class, learnerName, learnerSpec)); System.out.println("Setting metricLearner to: " + m_metricLearner); } optionString = Utils.getOption('G', options); if (optionString.length() != 0) { String[] regularizerSpec = Utils.splitOptions(optionString); String regularizerName = regularizerSpec[0]; regularizerSpec[0] = ""; m_metric.setRegularizer( (Regularizer) Utils.forName(Regularizer.class, regularizerName, regularizerSpec)); System.out.println("Setting regularizer to: " + regularizerName); } optionString = Utils.getOption('A', options); if (optionString.length() != 0) { String[] assignerSpec = Utils.splitOptions(optionString); String assignerName = assignerSpec[0]; assignerSpec[0] = ""; setAssigner((MPCKMeansAssigner) Utils.forName(MPCKMeansAssigner.class, assignerName, assignerSpec)); System.out.println("Setting assigner to: " + assignerName); } optionString = Utils.getOption('I', options); if (optionString.length() != 0) { String[] initializerSpec = Utils.splitOptions(optionString); String initializerName = initializerSpec[0]; initializerSpec[0] = ""; setInitializer((MPCKMeansInitializer) Utils.forName(MPCKMeansInitializer.class, initializerName, initializerSpec)); System.out.println("Setting initializer to: " + initializerName); } if (Utils.getFlag('U', options)) { setUseMultipleMetrics(true); System.out.println("Setting multiple metrics to: true"); } optionString = Utils.getOption('N', options); if (optionString.length() != 0) { setNumClusters(Integer.parseInt(optionString)); System.out.println("Setting numClusters to: " + m_NumClusters); } optionString = Utils.getOption('R', options); if (optionString.length() != 0) { setRandomSeed(Integer.parseInt(optionString)); System.out.println("Setting randomSeed to: " + m_RandomSeed); } optionString = Utils.getOption('l', options); if (optionString.length() != 0) { setLogTermWeight(Double.parseDouble(optionString)); System.out.println("Setting logTermWeight to: " + m_logTermWeight); } optionString = Utils.getOption('r', options); if (optionString.length() != 0) { setRegularizerTermWeight(Double.parseDouble(optionString)); System.out.println("Setting regularizerTermWeight to: " + m_regularizerTermWeight); } optionString = Utils.getOption('m', options); if (optionString.length() != 0) { setMustLinkWeight(Double.parseDouble(optionString)); System.out.println("Setting mustLinkWeight to: " + m_MLweight); } optionString = Utils.getOption('c', options); if (optionString.length() != 0) { setCannotLinkWeight(Double.parseDouble(optionString)); System.out.println("Setting cannotLinkWeight to: " + m_CLweight); } optionString = Utils.getOption('i', options); if (optionString.length() != 0) { setMaxIterations(Integer.parseInt(optionString)); System.out.println("Setting maxIterations to: " + m_maxIterations); } optionString = Utils.getOption('B', options); if (optionString.length() != 0) { setMaxBlankIterations(Integer.parseInt(optionString)); System.out.println("Setting maxBlankIterations to: " + m_maxBlankIterations); } optionString = Utils.getOption('O', options); if (optionString.length() != 0) { setClusterAssignmentsOutputFile(optionString); System.out.println("Setting clusterAssignmentsOutputFile to: " + m_ClusterAssignmentsOutputFile); } optionString = Utils.getOption('H', options); if (optionString.length() != 0) { setConstraintIncoherenceFile(optionString); System.out.println("Setting m_ConstraintIncoherenceFile to: " + m_ConstraintIncoherenceFile); } if (Utils.getFlag('V', options)) { setUseTransitiveConstraints(false); System.out.println("Setting useTransitiveConstraints to: false"); } }
From source file:MPCKMeans.java
License:Open Source License
public static void testCase() { try {// w w w . ja v a 2 s .com String dataset = new String("lowd"); //String dataset = new String("highd"); if (dataset.equals("lowd")) { //////// Low-D data // String datafile = "/u/ml/data/bio/arffFromPhylo/ecoli_K12-100.arff"; // String datafile = "/u/sugato/weka/data/digits-0.1-389.arff"; String datafile = "/u/sugato/weka/data/iris.arff"; int numPairs = 200, num = 0; // set up the data FileReader reader = new FileReader(datafile); Instances data = new Instances(reader); // Make the last attribute be the class int classIndex = data.numAttributes() - 1; data.setClassIndex(classIndex); // starts with 0 System.out.println("ClassIndex is: " + classIndex); // Remove the class labels before clustering Instances clusterData = new Instances(data); clusterData.deleteClassAttribute(); // create the pairs ArrayList labeledPair = InstancePair.getPairs(data, numPairs); System.out.println("Finished initializing constraint matrix"); MPCKMeans mpckmeans = new MPCKMeans(); mpckmeans.setUseMultipleMetrics(false); System.out.println("\nClustering the data using MPCKmeans...\n"); WeightedEuclidean metric = new WeightedEuclidean(); WEuclideanLearner metricLearner = new WEuclideanLearner(); // LearnableMetric metric = new WeightedDotP(); // MPCKMeansMetricLearner metricLearner = new DotPGDLearner(); // KL metric = new KL(); // KLGDLearner metricLearner = new KLGDLearner(); // ((KL)metric).setUseIDivergence(true); // BarHillelMetric metric = new BarHillelMetric(); // BarHillelMetricMatlab metric = new BarHillelMetricMatlab(); // XingMetric metric = new XingMetric(); // WeightedMahalanobis metric = new WeightedMahalanobis(); mpckmeans.setMetric(metric); mpckmeans.setMetricLearner(metricLearner); mpckmeans.setVerbose(false); mpckmeans.setRegularize(false); mpckmeans.setTrainable(new SelectedTag(TRAINING_INTERNAL, TAGS_TRAINING)); mpckmeans.setSeedable(true); mpckmeans.buildClusterer(labeledPair, clusterData, data, data.numClasses(), data.numInstances()); mpckmeans.getIndexClusters(); mpckmeans.printIndexClusters(); SemiSupClustererEvaluation eval = new SemiSupClustererEvaluation(mpckmeans.m_TotalTrainWithLabels, mpckmeans.m_TotalTrainWithLabels.numClasses(), mpckmeans.m_TotalTrainWithLabels.numClasses()); eval.evaluateModel(mpckmeans, mpckmeans.m_TotalTrainWithLabels, mpckmeans.m_Instances); System.out.println("MI=" + eval.mutualInformation()); System.out.print("FM=" + eval.pairwiseFMeasure()); System.out.print("\tP=" + eval.pairwisePrecision()); System.out.print("\tR=" + eval.pairwiseRecall()); } else if (dataset.equals("highd")) { //////// Newsgroup data String datafile = "/u/ml/users/sugato/groupcode/weka335/data/arffFromCCS/sanitized/different-1000_sanitized.arff"; //String datafile = "/u/ml/users/sugato/groupcode/weka335/data/20newsgroups/small-newsgroup_fromCCS.arff"; //String datafile = "/u/ml/users/sugato/groupcode/weka335/data/20newsgroups/same-100_fromCCS.arff"; // set up the data FileReader reader = new FileReader(datafile); Instances data = new Instances(reader); // Make the last attribute be the class int classIndex = data.numAttributes() - 1; data.setClassIndex(classIndex); // starts with 0 System.out.println("ClassIndex is: " + classIndex); // Remove the class labels before clustering Instances clusterData = new Instances(data); clusterData.deleteClassAttribute(); // create the pairs int numPairs = 0, num = 0; ArrayList labeledPair = new ArrayList(numPairs); Random rand = new Random(42); System.out.println("Initializing constraint matrix:"); while (num < numPairs) { int i = (int) (data.numInstances() * rand.nextFloat()); int j = (int) (data.numInstances() * rand.nextFloat()); int first = (i < j) ? i : j; int second = (i >= j) ? i : j; int linkType = (data.instance(first).classValue() == data.instance(second).classValue()) ? InstancePair.MUST_LINK : InstancePair.CANNOT_LINK; InstancePair pair = new InstancePair(first, second, linkType); if (first != second && !labeledPair.contains(pair)) { labeledPair.add(pair); //System.out.println(num + "th entry is: " + pair); num++; } } System.out.println("Finished initializing constraint matrix"); MPCKMeans mpckmeans = new MPCKMeans(); mpckmeans.setUseMultipleMetrics(false); System.out.println("\nClustering the highd data using MPCKmeans...\n"); LearnableMetric metric = new WeightedDotP(); MPCKMeansMetricLearner metricLearner = new DotPGDLearner(); // KL metric = new KL(); // KLGDLearner metricLearner = new KLGDLearner(); mpckmeans.setMetric(metric); mpckmeans.setMetricLearner(metricLearner); mpckmeans.setVerbose(false); mpckmeans.setRegularize(true); mpckmeans.setTrainable(new SelectedTag(TRAINING_INTERNAL, TAGS_TRAINING)); mpckmeans.setSeedable(true); mpckmeans.buildClusterer(labeledPair, clusterData, data, data.numClasses(), data.numInstances()); mpckmeans.getIndexClusters(); SemiSupClustererEvaluation eval = new SemiSupClustererEvaluation(mpckmeans.m_TotalTrainWithLabels, mpckmeans.m_TotalTrainWithLabels.numClasses(), mpckmeans.m_TotalTrainWithLabels.numClasses()); mpckmeans.getMetric().resetMetric(); // Vital: to reset m_attrWeights to 1 for proper normalization eval.evaluateModel(mpckmeans, mpckmeans.m_TotalTrainWithLabels, mpckmeans.m_Instances); System.out.println("MI=" + eval.mutualInformation()); System.out.print("FM=" + eval.pairwiseFMeasure()); System.out.print("\tP=" + eval.pairwisePrecision()); System.out.print("\tR=" + eval.pairwiseRecall()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:HierarchicalClusterer.java
License:Open Source License
public SelectedTag getLinkType() { return new SelectedTag(m_nLinkType, TAGS_LINK_TYPE); }