weka.attributeSelection.ASSearch Java Examples

The following examples show how to use weka.attributeSelection.ASSearch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WekaClassifier.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public IReconstructionPlan getConstructionPlan() {
	try {
		if (this.wrappedClassifier instanceof MLPipeline) {
			MLPipeline pipeline = (MLPipeline) this.wrappedClassifier;
			Classifier classifier = pipeline.getBaseClassifier();
			ASSearch searcher = pipeline.getPreprocessors().get(0).getSearcher();
			ASEvaluation evaluator = pipeline.getPreprocessors().get(0).getEvaluator();
			return new ReconstructionPlan(
					Arrays.asList(new ReconstructionInstruction(WekaClassifier.class.getMethod("createPipeline", String.class, List.class, String.class, List.class, String.class, List.class), searcher.getClass().getName(),
							((OptionHandler) searcher).getOptions(), evaluator.getClass().getName(), ((OptionHandler) evaluator).getOptions(), classifier.getClass().getName(), ((OptionHandler) classifier).getOptions())));
		} else {
			return new ReconstructionPlan(Arrays.asList(new ReconstructionInstruction(WekaClassifier.class.getMethod("createBaseClassifier", String.class, List.class), this.name, this.getOptionsAsList())));
		}
	} catch (NoSuchMethodException | SecurityException e) {
		throw new UnsupportedOperationException(e);
	}
}
 
Example #2
Source File: WekaClassifier.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public static WekaClassifier createPipeline(final String searcher, final List<String> searcherOptions, final String evaluator, final List<String> evaluatorOptions, final String classifier, final List<String> classifierOptions)
		throws Exception {
	ASSearch search = ASSearch.forName(searcher, searcherOptions.toArray(new String[0]));
	ASEvaluation eval = ASEvaluation.forName(evaluator, evaluatorOptions.toArray(new String[0]));
	Classifier c = AbstractClassifier.forName(classifier, classifierOptions.toArray(new String[0]));
	return new WekaClassifier(new MLPipeline(search, eval, c));
}
 
Example #3
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Gets the search specification string, which contains the class name of
  * the search method and any options to it
  *
  * @return the search string.
  */
 protected String getSearchSpec() {
   
   ASSearch s = getSearch();
   if (s instanceof OptionHandler) {
     return s.getClass().getName() + " "
+ Utils.joinOptions(((OptionHandler)s).getOptions());
   }
   return s.getClass().getName();
 }
 
Example #4
Source File: SupervisedFilterSelector.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public SupervisedFilterSelector(final ASSearch searcher, final ASEvaluation evaluator) {
	super();
	this.searcher = searcher;
	this.evaluator = evaluator;
	this.selector = new AttributeSelection();
	this.selector.setSearch(searcher);
	this.selector.setEvaluator(evaluator);
}
 
Example #5
Source File: MLPipeline.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public MLPipeline(final ASSearch searcher, final ASEvaluation evaluator, final Classifier baseClassifier) {
	super();
	if (baseClassifier == null) {
		throw new IllegalArgumentException("Base classifier must not be null!");
	}
	if (searcher != null && evaluator != null) {
		AttributeSelection selector = new AttributeSelection();
		selector.setSearch(searcher);
		selector.setEvaluator(evaluator);
		this.preprocessors.add(new SupervisedFilterSelector(searcher, evaluator, selector));
	}
	super.setClassifier(baseClassifier);
}
 
Example #6
Source File: SuvervisedFilterPreprocessor.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public SuvervisedFilterPreprocessor(final ASSearch searcher, final ASEvaluation evaluator) {
	super();
	this.searcher = searcher;
	this.evaluator = evaluator;
	this.selector = new AttributeSelection();
	this.selector.setSearch(searcher);
	this.selector.setEvaluator(evaluator);
}
 
Example #7
Source File: DecisionTable.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the search specification string, which contains the class name of
 * the search method and any options to it
 *
 * @return the search string.
 */
protected String getSearchSpec() {

  ASSearch s = getSearch();
  if (s instanceof OptionHandler) {
    return s.getClass().getName() + " "
    + Utils.joinOptions(((OptionHandler)s).getOptions());
  }
  return s.getClass().getName();
}
 
Example #8
Source File: DTNB.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the current search method
 * 
 * @return the search method used
 */
public ASSearch getSearch() {
  if (m_backwardWithDelete == null) {
    setUpSearch();
    //      setSearch(m_backwardWithDelete);
    m_search = m_backwardWithDelete;
  }
  return m_search;
}
 
Example #9
Source File: ComponentInstanceDatabaseGetter.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
private void next(final IKVStore resultSet) throws Exception {
	try {
		// Get pipeline
		ComponentInstance ci;
		if (resultSet.getAsString("searcher") != null && resultSet.getAsString("evaluator") != null) {
			ci = this.factory.convertToComponentInstance(
					new MLPipeline(ASSearch.forName(resultSet.getAsString("searcher"), null), ASEvaluation.forName(resultSet.getAsString("evaluator"), null), AbstractClassifier.forName(resultSet.getAsString("classifier"), null)));
		} else {
			ci = this.factory.convertToComponentInstance(new MLPipeline(new ArrayList<SupervisedFilterSelector>(), AbstractClassifier.forName(resultSet.getAsString("classifier"), null)));
		}

		// Get pipeline performance values (errorRate,dataset array)
		String[] results = resultSet.getAsString("results").split(";");
		HashMap<String, List<Double>> datasetPerformances = new HashMap<>();
		for (int j = 0; j < results.length; j++) {
			String[] errorRatePerformance = results[j].split(",");
			if (!datasetPerformances.containsKey(errorRatePerformance[0])) {
				datasetPerformances.put(errorRatePerformance[0], new ArrayList<Double>());
			}

			if (errorRatePerformance.length > 1) {
				datasetPerformances.get(errorRatePerformance[0]).add(Double.parseDouble(errorRatePerformance[1]));
			}

		}

		this.pipelines.add(ci);
		this.pipelinePerformances.add(datasetPerformances);
	} catch (ComponentNotFoundException e) {
		// Could not convert pipeline - component not in loaded configuration
		this.logger.warn("Could not convert component due to {}", e);
	}
}
 
Example #10
Source File: SupervisedFilterSelector.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public SupervisedFilterSelector(final ASSearch searcher, final ASEvaluation evaluator, final AttributeSelection selector) {
	super();
	this.searcher = searcher;
	this.evaluator = evaluator;
	this.selector = selector;
}
 
Example #11
Source File: WekaUtil.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String getPreprocessorDescriptor(final ASSearch c) {
	return getDescriptor(c);
}
 
Example #12
Source File: SupervisedFilterSelector.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public ASSearch getSearcher() {
	return this.searcher;
}
 
Example #13
Source File: DTNB.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sets the search method to use
 * 
 * @param search
 */
public void setSearch(ASSearch search) {
  // Search method cannot be changed.
  // Must be BackwardsWithDelete
  return;
}
 
Example #14
Source File: SuvervisedFilterPreprocessor.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public SuvervisedFilterPreprocessor(final ASSearch searcher, final ASEvaluation evaluator, final AttributeSelection selector) {
	super();
	this.searcher = searcher;
	this.evaluator = evaluator;
	this.selector = selector;
}
 
Example #15
Source File: SuvervisedFilterPreprocessor.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public ASSearch getSearcher() {
	return this.searcher;
}
 
Example #16
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -E &lt;attribute evaluator specification&gt;
 *  Full class name of attribute evaluator, followed
 *  by its options.
 *  eg: "weka.attributeSelection.CfsSubsetEval -L"
 *  (default weka.attributeSelection.CfsSubsetEval)</pre>
 * 
 * <pre> -S &lt;search method specification&gt;
 *  Full class name of search method, followed
 *  by its options.
 *  eg: "weka.attributeSelection.BestFirst -D 1"
 *  (default weka.attributeSelection.BestFirst)</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.trees.J48)</pre>
 * 
 * <pre> 
 * Options specific to classifier weka.classifiers.trees.J48:
 * </pre>
 * 
 * <pre> -U
 *  Use unpruned tree.</pre>
 * 
 * <pre> -C &lt;pruning confidence&gt;
 *  Set confidence threshold for pruning.
 *  (default 0.25)</pre>
 * 
 * <pre> -M &lt;minimum number of instances&gt;
 *  Set minimum number of instances per leaf.
 *  (default 2)</pre>
 * 
 * <pre> -R
 *  Use reduced error pruning.</pre>
 * 
 * <pre> -N &lt;number of folds&gt;
 *  Set number of folds for reduced error
 *  pruning. One fold is used as pruning set.
 *  (default 3)</pre>
 * 
 * <pre> -B
 *  Use binary splits only.</pre>
 * 
 * <pre> -S
 *  Don't perform subtree raising.</pre>
 * 
 * <pre> -L
 *  Do not clean up after the tree has been built.</pre>
 * 
 * <pre> -A
 *  Laplace smoothing for predicted probabilities.</pre>
 * 
 * <pre> -Q &lt;seed&gt;
 *  Seed for random data shuffling (default 1).</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 {

  // same for attribute evaluator
  String evaluatorString = Utils.getOption('E', options);
  if (evaluatorString.length() == 0)
    evaluatorString = weka.attributeSelection.CfsSubsetEval.class.getName();
  String [] evaluatorSpec = Utils.splitOptions(evaluatorString);
  if (evaluatorSpec.length == 0) {
    throw new Exception("Invalid attribute evaluator specification string");
  }
  String evaluatorName = evaluatorSpec[0];
  evaluatorSpec[0] = "";
  setEvaluator(ASEvaluation.forName(evaluatorName, evaluatorSpec));

  // same for search method
  String searchString = Utils.getOption('S', options);
  if (searchString.length() == 0)
    searchString = weka.attributeSelection.BestFirst.class.getName();
  String [] searchSpec = Utils.splitOptions(searchString);
  if (searchSpec.length == 0) {
    throw new Exception("Invalid search specification string");
  }
  String searchName = searchSpec[0];
  searchSpec[0] = "";
  setSearch(ASSearch.forName(searchName, searchSpec));

  super.setOptions(options);
}
 
Example #17
Source File: AttributeSelection.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the name of the search method
 *
 * @return the name of the search method as a string
 */
public ASSearch getSearch() {
  
    return m_ASSearch;
}
 
Example #18
Source File: AttributeSelection.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Set search class
 * 
 * @param search the search class to use
 */
public void setSearch(ASSearch search) {
  m_ASSearch = search;
}
 
Example #19
Source File: DecisionTable.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
  * Parses the options for this object. <p/>
  *
  <!-- options-start -->
  * Valid options are: <p/>
  * 
  * <pre> -S &lt;search method specification&gt;
  *  Full class name of search method, followed
  *  by its options.
  *  eg: "weka.attributeSelection.BestFirst -D 1"
  *  (default weka.attributeSelection.BestFirst)</pre>
  * 
  * <pre> -X &lt;number of folds&gt;
  *  Use cross validation to evaluate features.
  *  Use number of folds = 1 for leave one out CV.
  *  (Default = leave one out CV)</pre>
  * 
  * <pre> -E &lt;acc | rmse | mae | auc&gt;
  *  Performance evaluation measure to use for selecting attributes.
  *  (Default = accuracy for discrete class and rmse for numeric class)</pre>
  * 
  * <pre> -I
  *  Use nearest neighbour instead of global table majority.</pre>
  * 
  * <pre> -R
  *  Display decision table rules.
  * </pre>
  * 
  * <pre> 
  * Options specific to search method weka.attributeSelection.BestFirst:
  * </pre>
  * 
  * <pre> -P &lt;start set&gt;
  *  Specify a starting set of attributes.
  *  Eg. 1,3,5-7.</pre>
  * 
  * <pre> -D &lt;0 = backward | 1 = forward | 2 = bi-directional&gt;
  *  Direction of search. (default = 1).</pre>
  * 
  * <pre> -N &lt;num&gt;
  *  Number of non-improving nodes to
  *  consider before terminating search.</pre>
  * 
  * <pre> -S &lt;num&gt;
  *  Size of lookup cache for evaluated subsets.
  *  Expressed as a multiple of the number of
  *  attributes in the data set. (default = 1)</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 optionString;

   resetOptions();

   optionString = Utils.getOption('X',options);
   if (optionString.length() != 0) {
     m_CVFolds = Integer.parseInt(optionString);
   }

   m_useIBk = Utils.getFlag('I',options);

   m_displayRules = Utils.getFlag('R',options);

   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("auc")) {
setEvaluationMeasure(new SelectedTag(EVAL_AUC, TAGS_EVALUATION));
     } else {
throw new IllegalArgumentException("Invalid evaluation measure");
     }
   }

   String searchString = Utils.getOption('S', options);
   if (searchString.length() == 0)
     searchString = weka.attributeSelection.BestFirst.class.getName();
   String [] searchSpec = Utils.splitOptions(searchString);
   if (searchSpec.length == 0) {
     throw new IllegalArgumentException("Invalid search specification string");
   }
   String searchName = searchSpec[0];
   searchSpec[0] = "";
   setSearch(ASSearch.forName(searchName, searchSpec));
 }
 
Example #20
Source File: DecisionTable.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the current search method
 * 
 * @return the search method used
 */
public ASSearch getSearch() {
  return m_search;
}
 
Example #21
Source File: DecisionTable.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the search method to use
 * 
 * @param search
 */
public void setSearch(ASSearch search) {
  m_search = search;
}
 
Example #22
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the search method used
 *
 * @return the search method
 */
public ASSearch getSearch() {
  return m_Search;
}
 
Example #23
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the search method
 *
 * @param search the search method with all options set.
 */
public void setSearch(ASSearch search) {
  m_Search = search;
}