Feature engineering

From UCSB-NLP-Chang/Skill-Usage · View interactive version

Feature engineering is an AI agent skill from the GitHub repository UCSB-NLP-Chang/Skill-Usage. Engineer dataset features before ML or Causal Inference. Methods include encoding categorical variables, scaling numerics, creating interactions, and selecting relevant features.

How to use this skill

Skill file

Feature Engineering Framework

Comprehensive, modular feature engineering framework general tabular datasets. Provides strategy-based operations including numerical scaling, categorical encoding, polynomial features, and feature selection through a configurable pipeline.

Core Components

FeatureEngineeringStrategies

Collection of static methods for feature engineering operations:

Numerical Features (if intepretability is not a concern)
Categorical Features
Binary Features
Data Quality Validation
Feature Selection

FeatureEngineeringPipeline

Orchestrates multiple feature engineering steps with logging.

CRITICAL REQUIREMENTS:

  1. ALL output features MUST be numeric (int or float) - DID analysis cannot use string/object columns
  2. Preview data types BEFORE processing: df.dtypes and df.head() to check actual values
  3. Encode ALL categorical variables - strings like "degree", "age_range" must be converted to numbers
  4. Verify output: Final dataframe should have df.select_dtypes(include='number').shape[1] == df.shape[1] - 1 (excluding ID column)

Usage Example

from feature_engineering import FeatureEngineeringStrategies, FeatureEngineeringPipeline

# Create pipeline
pipeline = FeatureEngineeringPipeline(name="Demographics")

# Add feature engineering steps
pipeline.add_step(
    FeatureEngineeringStrategies.convert_to_binary,
    columns=['<column5>', '<column2>'],
    description="Convert binary survey responses to 0/1"
).add_step(
    FeatureEngineeringStrategies.encode_categorical,
    columns=['<column3>', '<column7>'],
    method='onehot',
    description="One-hot encode categorical features"
).add_step(
    FeatureEngineeringStrategies.scale_numerical,
    columns=['<column10>', '<column1>'],
    method='standard',
    description="Standardize numerical features"
).add_step(
    FeatureEngineeringStrategies.validate_numeric_features,
    exclude_cols=['<ID Column>'],
    description="Verify all features are numeric before modeling"
).add_step(
    FeatureEngineeringStrategies.validate_no_constants,
    exclude_cols=['<ID Column>'],
    description="Remove constant columns with no predictive value"
).add_step(
    FeatureEngineeringStrategies.select_features_variance,
    columns=[],  # Empty = auto-select all numerical
    threshold=0.01,
    description="Remove low-variance features"
)

# Execute pipeline
# df_complete: complete returns original columns and the engineered features
df_complete = pipeline.execute(your_cleaned_df, verbose=True)

# Shortcut: Get the ID Column with the all needed enigneered features
engineered_features = pipeline.get_engineered_features()
df_id_pure_features = df_complete[['<ID Column>']+engineered_features]

# Get execution log
log_df = pipeline.get_log()

Input

Output

Key Features

Best Practices

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.