weka.attributeSelection.ASEvaluation Java Examples

The following examples show how to use weka.attributeSelection.ASEvaluation. 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: 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 #3
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 #4
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 #5
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 #6
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 #7
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Gets the evaluator specification string, which contains the class name of
  * the attribute evaluator and any options to it
  *
  * @return the evaluator string.
  */
 protected String getEvaluatorSpec() {
   
   ASEvaluation e = getEvaluator();
   if (e instanceof OptionHandler) {
     return e.getClass().getName() + " "
+ Utils.joinOptions(((OptionHandler)e).getOptions());
   }
   return e.getClass().getName();
 }
 
Example #8
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 ASEvaluation c) {
	return getDescriptor(c);
}
 
Example #9
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 #10
Source File: SupervisedFilterSelector.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public ASEvaluation getEvaluator() {
	return this.evaluator;
}
 
Example #11
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 #12
Source File: SuvervisedFilterPreprocessor.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public ASEvaluation getEvaluator() {
	return this.evaluator;
}
 
Example #13
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 #14
Source File: AttributeSelection.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the name of the attribute/subset evaluator
 *
 * @return the name of the attribute/subset evaluator as a string
 */
public ASEvaluation getEvaluator() {
  
    return m_ASEvaluator;
}
 
Example #15
Source File: AttributeSelection.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * set attribute/subset evaluator
 * 
 * @param evaluator the evaluator to use
 */
public void setEvaluator(ASEvaluation evaluator) {
  m_ASEvaluator = evaluator;
}
 
Example #16
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the attribute evaluator used
 *
 * @return the attribute evaluator
 */
public ASEvaluation getEvaluator() {
  return m_Evaluator;
}
 
Example #17
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the attribute evaluator
 *
 * @param evaluator the evaluator with all options set.
 */
public void setEvaluator(ASEvaluation evaluator) {
  m_Evaluator = evaluator;
}