Skip to content

FeatureGenerator


class atom.feature_engineering.FeatureGenerator(strategy="dfs", n_features=None, operators=None, n_jobs=1, verbose=0, logger=None, random_state=None, **kwargs) [source]

Create new combinations of existing features to capture the non-linear relations between the original features. This class can be accessed from atom through the feature_generation method. Read more in the user guide.

Parameters: strategy: str, optional (default="dfs")
Strategy to crate new features. Choose from:
  • "dfs": Deep Feature Synthesis.
  • "gfg": Genetic Feature Generation.

n_features: int or None, optional (default=None)
Maximum number of newly generated features to add to the dataset. If None, select all created features.

operators: str, list, tuple or None, optional (default=None)
Name of the operators to be used on the features. None to use all. Choose from: add, sub, mul, div, sqrt, log, sin, cos, tan.

n_jobs: int, optional (default=1)
Number of cores to use for parallel processing.
  • If >0: Number of cores to use.
  • If -1: Use all available cores.
  • If <-1: Use available_cores - 1 + n_jobs.
verbose: int, optional (default=0)
Verbosity level of the class. Choose from:
  • 0 to not print anything.
  • 1 to print basic information.
  • 2 to print detailed information.
logger: str, Logger or None, optional (default=None)
  • If None: Doesn't save a logging file.
  • If str: Name of the log file. Use "auto" for automatic naming.
  • Else: Python logging.Logger instance.

random_state: int or None, optional (default=None)
Seed used by the random number generator. If None, the random number generator is the RandomState instance used by np.random.

**kwargs
Additional keyword arguments for the SymbolicTransformer instance. Only for the gfg strategy.

Tip

dfs can create many new features and not all of them will be useful. Use FeatureSelector to reduce the number of features!

Warning

Using the div, log or sqrt operators can return new features with inf or NaN values. Check the warnings that may pop up or use atom's missing property.

Warning

When using dfs with n_jobs>1, make sure to protect your code with if __name__ == "__main__". Featuretools uses dask, which uses python multiprocessing for parallelization. The spawn method on multiprocessing starts a new python process, which requires it to import the __main__ module before it can do its task.


Attributes

Attributes:

gfg: SymbolicTransformer
Object used to calculate the genetic features. Only for the gfg strategy.

genetic_features: pd.DataFrame
Information on the newly created non-linear features. Only for the gfg strategy. Columns include:
  • name: Name of the feature (automatically created).
  • description: Operators used to create this feature.
  • fitness: Fitness score.
  • feature_names_in_: np.array
    Names of features seen during fit.

    n_features_in_: int
    Number of features seen during fit.


Methods

fit Fit to data.
fit_transform Fit to data, then transform it.
get_params Get parameters for this estimator.
log Write information to the logger and print to stdout.
save Save the instance to a pickle file.
set_params Set the parameters of this estimator.
transform Transform the data.


method fit(X, y) [source]

Fit to data.

Parameters:

X: dataframe-like
Feature set with shape=(n_samples, n_features).

y: int, str or sequence
  • If int: Index of the target column in X.
  • If str: Name of the target column in X.
  • Else: Target column with shape=(n_samples,).
Returns: FeatureGenerator
Fitted instance of self.


method fit_transform(X, y) [source]

Fit to data, then transform it.

Parameters:

X: dataframe-like
Feature set with shape=(n_samples, n_features).

y: int, str or sequence
  • If int: Index of the target column in X.
  • If str: Name of the target column in X.
  • Else: Target column with shape=(n_samples,).
Returns: X: pd.DataFrame
Feature set with the newly generated features.


method get_params(deep=True) [source]

Get parameters for this estimator.

Parameters:

deep: bool, optional (default=True)
If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns: dict
Parameter names mapped to their values.


method log(msg, level=0) [source]

Write a message to the logger and print it to stdout.

Parameters:

msg: str
Message to write to the logger and print to stdout.

level: int, optional (default=0)
Minimum verbosity level to print the message.


method save(filename="auto") [source]

Save the instance to a pickle file.

Parameters: filename: str, optional (default="auto")
Name of the file. Use "auto" for automatic naming.


method set_params(**params) [source]

Set the parameters of this estimator.

Parameters: **params: dict
Estimator parameters.
Returns: FeatureGenerator
Estimator instance.


method transform(X, y=None) [source]

Generate new features.

Parameters:

X: dataframe-like
Feature set with shape=(n_samples, n_features).

y: int, str, sequence or None, optional (default=None)
Does nothing. Implemented for continuity of the API.

Returns: X: pd.DataFrame
Feature set with the newly generated features.


Example

from atom import ATOMClassifier

atom = ATOMClassifier(X, y)
atom.feature_generation(strategy="dfs", n_features=3, operators=["add", "mul"])
from atom.feature_engineering import FeatureGenerator

generator = FeatureGenerator(strategy="dfs", n_features=3, operators=["add", "mul"])
generator.fit(X_train, y_train)
X = generator.transform(X)
Back to top