Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.yahoo.labs.samoa.instances.Instance;
import moa.classifiers.AbstractClassifier;
import moa.classifiers.MultiClassClassifier;
import moa.classifiers.Regressor;
import moa.classifiers.meta.AdaptiveRandomForest;
import moa.core.Measurement;
import moa.core.Utils;
Expand Down Expand Up @@ -64,7 +65,7 @@ public String getPurposeString() {

public ClassOption featureImportanceLearnerOption = new ClassOption("featureImportanceLearner", 'l',
"Learner used to build the model from which the feature importances are extracted",
FeatureImportanceClassifier.class, "moa.learners.featureanalysis.FeatureImportanceHoeffdingTree");
FeatureImportanceLearner.class, "moa.learners.featureanalysis.FeatureImportanceHoeffdingTree");

public FlagOption doNotNormalizeFeatureScoreOption = new FlagOption("doNotNormalizeFeatureScore", 'n',
"If set the feature importances will not be normalized");
Expand All @@ -84,7 +85,7 @@ public String getPurposeString() {
protected PrintStream debugStream;

protected long instancesSeen = 0;
protected FeatureImportanceClassifier featureImportanceClassifierLearner;
protected FeatureImportanceLearner featureImportanceClassifierLearner;

protected double mean = -1.0;
protected double median = -1.0;
Expand Down Expand Up @@ -113,7 +114,14 @@ protected void createDebugOutputFile() {
public void resetLearningImpl() {
this.instancesSeen = 0;
this.featureImportanceClassifierLearner = null;
this.featureImportanceClassifierLearner = (FeatureImportanceClassifier) getPreparedClassOption(this.featureImportanceLearnerOption);
this.featureImportanceClassifierLearner = (FeatureImportanceLearner) getPreparedClassOption(this.featureImportanceLearnerOption);
// FeatureImportanceLearner covers regressors as well, so they reach the option chooser
// here even though this wrapper reads the votes as a class distribution.
if (this.featureImportanceClassifierLearner instanceof Regressor) {
throw new IllegalArgumentException(this.getClass().getName() + " needs a classifier, "
+ "but " + this.featureImportanceClassifierLearner.getClass().getName()
+ " is a regressor.");
}
this.featureImportanceClassifierLearner.resetLearning();
this.createDebugOutputFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @version $Revision: 1 $
*/
public class FeatureImportanceHoeffdingTree extends AbstractClassifier implements MultiClassClassifier,
CapabilitiesHandler, FeatureImportanceClassifier {
CapabilitiesHandler, FeatureImportanceLearner {

public ClassOption treeLearnerOption = new ClassOption("treeLearner", 'l',
"Decision Tree learner.", HoeffdingTree.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @version $Revision: 1 $
*/
public class FeatureImportanceHoeffdingTreeEnsemble extends AbstractClassifier implements MultiClassClassifier,
CapabilitiesHandler, FeatureImportanceClassifier {
CapabilitiesHandler, FeatureImportanceLearner {

public ClassOption ensembleLearnerOption = new ClassOption("ensembleLearner", 'l',
"Ensemble learner to train and analyze.", Classifier.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* FeatureScore.java
* Copyright (C) 2020 University of Waikato, Hamilton, New Zealand
* @author Heitor Murilo Gomes (hgomes at waikato dot ac dot nz)
* FeatureImportanceLearner.java
* Copyright (C) 2026 University of Waikato, Hamilton, New Zealand
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,34 +21,37 @@
import moa.classifiers.Classifier;

/**
* Feature Importance Classifier
* Feature Importance Learner
*
* <p>This interface defines the methods to be implemented on a Classifier to allow it to produce feature importances.
* </p>
* <p>This interface defines the methods to be implemented on a learner to allow it to produce
* feature importances. Nothing here depends on the kind of prediction being made, so it covers
* classifiers and regressors alike; a regressor additionally declares
* {@link moa.classifiers.Regressor} so that the regression tasks and the regression tab of the
* GUI pick it up.</p>
*
* <p>See details in:<br> Heitor Murilo Gomes, Rodrigo Fernandes de Mello, Bernhard Pfahringer, Albert Bifet.
* Feature Scoring using Tree-Based Ensembles for Evolving Data Streams.
* <p>See details in:<br> Heitor Murilo Gomes, Rodrigo Fernandes de Mello, Bernhard Pfahringer,
* Albert Bifet. Feature Scoring using Tree-Based Ensembles for Evolving Data Streams.
* IEEE International Conference on Big Data (pp. 761-769), 2019</p>
* </p>
*
* @author Heitor Murilo Gomes
*/
public interface FeatureImportanceClassifier extends Classifier {
public interface FeatureImportanceLearner extends Classifier {

/**
* Obtain the current importance for each feature.
*
* @param normalize whether to rescale the scores before returning them
* @return array containing the importance/score estimated for each feature
*/
double[] getFeatureImportances(boolean normalize);

/**
* The output is a double array where values indicates the
* original feature index and the order of the array its
* ranking. The size of this array is expected to be less than
* the complete set of features.
* @param k
* @param normalize
* The output is an array where values indicate the original feature index and the order of
* the array its ranking. The size of this array is expected to be less than or equal to the
* complete set of features.
*
* @param k how many features to return
* @param normalize whether to rank the normalized scores
* @return the k features with the highest scores.
*/
int[] getTopKFeatures(int k, boolean normalize);
Expand Down
Loading