You are viewing documentation about an older version (1.0.9). View latest version

snowflake.ml.modeling.feature_selection.SequentialFeatureSelectorΒΆ

class snowflake.ml.modeling.feature_selection.SequentialFeatureSelector(*, estimator, n_features_to_select='auto', tol=None, direction='forward', scoring=None, cv=5, n_jobs=None, input_cols: Optional[Union[str, Iterable[str]]] = None, output_cols: Optional[Union[str, Iterable[str]]] = None, label_cols: Optional[Union[str, Iterable[str]]] = None, drop_input_cols: Optional[bool] = False, sample_weight_col: Optional[str] = None)ΒΆ

Bases: BaseTransformer

Transformer that performs Sequential Feature Selection For more details on this class, see sklearn.feature_selection.SequentialFeatureSelector

estimator: estimator instance

An unfitted estimator.

n_features_to_select: β€œauto”, int or float, default=”auto”

If β€œauto”, the behaviour depends on the tol parameter:

  • if tol is not None, then features are selected while the score change does not exceed tol.

  • otherwise, half of the features are selected.

If integer, the parameter is the absolute number of features to select. If float between 0 and 1, it is the fraction of features to select.

tol: float, default=None

If the score is not incremented by at least tol between two consecutive feature additions or removals, stop adding or removing.

tol can be negative when removing features using direction=”backward”. It can be useful to reduce the number of features at the cost of a small decrease in the score.

tol is enabled only when n_features_to_select is β€œauto”.

direction: {β€˜forward’, β€˜backward’}, default=’forward’

Whether to perform forward selection or backward selection.

scoring: str or callable, default=None

A single str (see scoring_parameter) or a callable (see scoring) to evaluate the predictions on the test set.

NOTE that when using a custom scorer, it should return a single value.

If None, the estimator’s score method is used.

cv: int, cross-validation generator or an iterable, default=None

Determines the cross-validation splitting strategy. Possible inputs for cv are:

  • None, to use the default 5-fold cross validation,

  • integer, to specify the number of folds in a (Stratified)KFold,

  • CV splitter,

  • An iterable yielding (train, test) splits as arrays of indices.

For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used. These splitters are instantiated with shuffle=False so the splits will be the same across calls.

Refer User Guide for the various cross-validation strategies that can be used here.

n_jobs: int, default=None

Number of jobs to run in parallel. When evaluating a new feature to add or remove, the cross-validation procedure is parallel over the folds. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.

input_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that contain features. If this parameter is not specified, all columns in the input DataFrame except the columns specified by label_cols and sample-weight_col parameters are considered input columns.

label_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that contain labels. This is a required param for estimators, as there is no way to infer these columns. If this parameter is not specified, then object is fitted without labels(Like a transformer).

output_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that will store the output of predict and transform operations. The length of output_cols mus match the expected number of output columns from the specific estimator or transformer class used. If this parameter is not specified, output column names are derived by adding an OUTPUT_ prefix to the label column names. These inferred output column names work for estimator’s predict() method, but output_cols must be set explicitly for transformers.

sample_weight_col: Optional[str]

A string representing the column name containing the examples’ weights. This argument is only required when working with weighted datasets.

drop_input_cols: Optional[bool], default=False

If set, the response of predict(), transform() methods will not contain input columns.

Methods

fit(dataset)

Learn the features to select from X For more details on this function, see sklearn.feature_selection.SequentialFeatureSelector.fit

score(dataset)

Method not supported for this class.

set_input_cols(input_cols)

Input columns setter.

to_sklearn()

Get sklearn.feature_selection.SequentialFeatureSelector object.

transform(dataset)

Reduce X to the selected features For more details on this function, see sklearn.feature_selection.SequentialFeatureSelector.transform

Attributes

model_signatures

Returns model signature of current class.