feature-engine Documentation

repository·main·Indexed 25 days ago

https://github.com/feature-engine/feature_engine

A Python library for feature engineering and selection in machine learning workflows. It provides a comprehensive suite of transformers for imputation, encoding, discretisation, outlier handling, variable transformation, and feature creation. All transformers are fully compatible with the Scikit-learn API, implementing fit() and transform() methods for seamless integration into Scikit-learn Pipeline objects and returning pandas DataFrames for EDA friendliness.

Tokens
103.9K
Snippets
160
Records
598
Agent score
79%

What's inside feature-engine

  1. Overview of Feature-engine capabilities

    main

    Feature-engine is an open-source Python library designed for feature engineering and selection in machine learning workflows. It provides an exhaustive battery of transformations that are compatible with Pandas and Scikit-learn.

    Key capabilities include:

    • Imputation Methods: Handling missing data.
    • Encoding Methods: Converting categorical variables into numerical formats.
    • Discretisation Methods: Binning continuous variables.
    • Outlier Handling: Removing or censoring outliers.
    • Variable Transformation: Mathematical transformations of variables.
    • Feature Selection: Algorithms to select the most relevant features.
    • Feature Creation: Combining variables into new features.
  2. What is feature-engine?

    main

    feature-engine is an open source Python package designed for data pre-processing and transformation. It provides a collection of frequently used feature engineering techniques that are designed to be used just like sklearn classes. This allows for seamless integration into machine learning pipelines.

    The library includes transformers for:

    • Imputation Methods
    • Encoding Methods
    • Discretisation methods
    • Outlier Handling methods
    • Variable Transformation methods
  3. Overview of Categorical Encoding Transformers

    main

    Feature-engine provides several encoders that replace categorical variables with estimated or arbitrary numbers. These transformers are designed for different machine learning tasks (Regression, Classification, or Multi-class) and handle different data types.

    Key Characteristics:

    TransformerRegressionClassificationMulti-classDescription
    OneHotEncoder()Adds dummy variables to represent each category
    OrdinalEncoder()Replaces categories with an integer
    CountEncoder()Replaces categories with their count or frequency
    MeanEncoder()xReplaces categories with the target mean value
    WoEEncoder()xxReplaces categories with the weight of the evidence
    DecisionTreeEncoder()Replaces categories with the predictions of a decision tree
    RareLabelEncoder()Groups infrequent categories into a single one

    Note: √ indicates support, x indicates no support.

  4. Overview of Feature Creation in feature-engine

    main

    Feature creation involves constructing new variables from a dataset's original features to improve machine learning model performance or capture complex relationships.

    Feature-engine provides several transformers to automate this process:

    • Categorical Encoding: e.g., OneHotEncoder to create dummy variables.
    • Time Series: e.g., LagFeatures and WindowFeatures to create features from past values.
    • Datetime & Text: Extraction of features from datetime variables and text data.
    • Mathematical/Statistical Combinations: Using the creation module to combine numerical variables through various operations.

    Note: Creating new features can significantly increase dataset dimensionality (e.g., high-cardinality one-hot encoding or high-power polynomial combinations), which may impact certain algorithms like decision trees.

  5. Overview of Feature Selection in Feature-engine

    main
    Feature-engine provides a suite of feature selection transformers designed to drop subsets of variables with low predictive value. These transformers are categorized by their selection strategy: based on feature characteristics, machine learning model performance, financial industry standards, or alternative algorithmic approaches. They are designed to be used within machine learning pipelines to improve model performance and reduce dimensionality.
  6. Overview of Feature-engine imputation methods

    main

    Feature-engine provides several univariate imputation methods to handle missing data in numerical and categorical variables. These methods can be categorized by their approach and the type of data they target:

    Numerical Imputation

    • MeanImputer(): Replaces missing values with the mean or median.
    • ArbitraryImputer(): Replaces missing values with a user-defined arbitrary value.
    • EndTailImputer(): Replaces missing values with a value at the tail of the distribution (e.g., using IQR or standard deviation).

    Categorical Imputation

    • CategoricalImputer(): Replaces missing values with the most frequent category or a specific new label (e.g., 'Missing').

    Mixed/Universal Imputation

    • RandomSampleImputer(): Replaces missing values with random values drawn from the variable's distribution (works for both numerical and categorical).
    • MissingIndicator(): Adds a binary flag (0 or 1) to indicate if a value was missing. This is typically used alongside other imputation methods.
    • DropMissingData(): Removes entire rows containing missing values (Complete Case Analysis).
  7. Explore Feature-engine API categories

    main

    Feature-engine provides a comprehensive suite of transformers organized into several functional categories. You can use these categories to build feature engineering pipelines for machine learning models:

    • Transformation: Includes imputation, encoding, discretisation, outlier handling, variable transformation, and scaling.
    • Creation: Tools for creating new features from datetime, text, or other existing variables.
    • Selection: Methods for selecting the most relevant features for your model.
    • Time series: Specialized transformers for temporal data.
    • Other: Includes general preprocessing and wrappers.
    • Pipeline: Integration tools for building feature engineering pipelines.
    • Datasets: Sample datasets for testing and demonstration.
    • Tools: Variable handling utilities.
  8. Discretise continuous variables with Feature-engine

    main

    Feature-engine provides several discretisation transformers to convert continuous variables into discrete features by sorting values into intervals. This is useful for preparing data for models that require categorical inputs or for simplifying complex continuous distributions.

    Available transformers include:

    • EqualFrequencyDiscretiser(): Sorts values into intervals containing a similar number of observations.
    • EqualWidthDiscretiser(): Sorts values into intervals of equal size (width).
    • ArbitraryDiscretiser(): Sorts values into intervals predefined by the user.
    • DecisionTreeDiscretiser(): Replaces values with predictions from a decision tree, resulting in discrete categories.
    • GeometricWidthDiscretiser(): Sorts variables into geometrical intervals.
  9. Use time series features in Feature-engine

    main
    Feature-engine provides a suite of time series transformers located in the feature_engine.timeseries module. These transformers are designed to create new features from time series data, which can be used to improve machine learning models that process temporal information. The module includes specialized functionality for forecasting tasks.
  10. Extract features from datetime data

    main
    Feature-engine provides a suite of datetime transformers designed to extract various temporal features from existing datetime or object-like columns. These transformers can be used to convert raw datetime data into more informative features for machine learning models, such as day of the week, month, year, or specific time components.
  11. Available feature-engine transformers

    main

    Feature-engine provides an exhaustive collection of transformers for various feature engineering tasks. These transformers automatically recognize numerical, categorical, and datetime variables.

    Supported transformation categories include:

    • Missing data imputation
    • Encoding of categorical features
    • Discretisation
    • Outlier capping or removal
    • Feature transformation
    • Feature combinations
    • Feature scaling
    • Feature extraction (from datetime, text, and time series)
    • Preprocessing
    • Feature selection