Record Class EnsembleSelection

java.lang.Object
java.lang.Record
smile.feature.selection.EnsembleSelection
Record Components:
feature - The feature name.
importance - The variable importance score.
All Implemented Interfaces:
Comparable<EnsembleSelection>

public record EnsembleSelection(String feature, double importance) extends Record implements Comparable<EnsembleSelection>
Feature selection using tree ensemble models (such as Random Forest or Gradient Tree Boost).

Ensemble methods measure the importance of features by aggregating the impurity decrease (such as Gini impurity or variance reduction) across all trees in the ensemble. Features that appear frequently in splits yielding large impurity reductions achieve higher importance scores.

  • Constructor Details

    • EnsembleSelection

      public EnsembleSelection(String feature, double importance)
      Creates an instance of a EnsembleSelection record class.
      Parameters:
      feature - the value for the feature record component
      importance - the value for the importance record component
  • Method Details

    • compareTo

      public int compareTo(EnsembleSelection other)
      Specified by:
      compareTo in interface Comparable<EnsembleSelection>
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • of

      public static EnsembleSelection[] of(StructType schema, double[] importance)
      Constructs ensemble feature selection scores from a feature schema and importance vector.
      Parameters:
      schema - the predictors schema.
      importance - the importance scores corresponding to each schema field.
      Returns:
      an array of ensemble selection scores.
    • of

      public static EnsembleSelection[] of(DataFrameClassifier model)
      Extracts ensemble selection scores from a trained classification model.
      Parameters:
      model - the trained classification model.
      Returns:
      an array of ensemble selection scores.
    • of

      public static EnsembleSelection[] of(DataFrameRegression model)
      Extracts ensemble selection scores from a trained regression model.
      Parameters:
      model - the trained regression model.
      Returns:
      an array of ensemble selection scores.
    • fit

      public static EnsembleSelection[] fit(Formula formula, DataFrame data)
      Fits an ensemble model to calculate feature importance scores. Automatically chooses classification or regression based on the response variable type.
      Parameters:
      formula - a symbolic description of the model to be fitted.
      data - the data frame of explanatory and response variables.
      Returns:
      an array of ensemble selection scores.
    • fit

      public static EnsembleSelection[] fit(Formula formula, DataFrame data, Properties props)
      Fits an ensemble model to calculate feature importance scores with hyperparameter options. Automatically chooses classification or regression based on the response variable type.
      Parameters:
      formula - a symbolic description of the model to be fitted.
      data - the data frame of explanatory and response variables.
      props - the hyperparameters.
      Returns:
      an array of ensemble selection scores.
    • fit

      public static EnsembleSelection[] fit(DataFrame data, String response)
      Fits an ensemble model to calculate feature importance scores.
      Parameters:
      data - the data frame of explanatory and response variables.
      response - the column name of the response variable.
      Returns:
      an array of ensemble selection scores.
    • fit

      public static EnsembleSelection[] fit(DataFrame data, String response, Properties props)
      Fits an ensemble model to calculate feature importance scores with hyperparameter options.
      Parameters:
      data - the data frame of explanatory and response variables.
      response - the column name of the response variable.
      props - the hyperparameters.
      Returns:
      an array of ensemble selection scores.
    • top

      public static String[] top(EnsembleSelection[] scores, int k)
      Returns the names of the top k features in descending order of importance.
      Parameters:
      scores - the ensemble selection scores.
      k - the number of top features to return.
      Returns:
      the top k feature names.
    • threshold

      public static String[] threshold(EnsembleSelection[] scores, double minImportance)
      Returns the names of features with importance score greater than or equal to a threshold, sorted in descending order of importance.
      Parameters:
      scores - the ensemble selection scores.
      minImportance - the minimum importance threshold.
      Returns:
      the selected feature names.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • feature

      public String feature()
      Returns the value of the feature record component.
      Returns:
      the value of the feature record component
    • importance

      public double importance()
      Returns the value of the importance record component.
      Returns:
      the value of the importance record component