Skip to main content

Feature Fabrica logo

⚙️ The Framework to Simplify and Scale Feature Engineering ⚙️

Open in Colab

PyPI version Stars Issues License Contributors Code Quality

For data scientists, ML engineers, and AI researchers who want to simplify feature engineering, manage complex dependencies, and boost productivity.


Introduction

Feature Fabrica is an open-source Python library designed to improve engineering practices and transparency in feature engineering. It allows users to define features declaratively using YAML, manage dependencies between features, and apply complex transformations in a scalable and convenient manner.

By providing a structured approach to feature engineering, Feature Fabrica aims to save time, reduce errors, and enhance the transparency and reproducibility of your machine learning workflows. Whether you're working on small projects or managing large-scale pipelines, Feature Fabrica is designed to meet your needs.

Key Features

  • 📝 Declarative Feature Definitions: Define features, data types, and dependencies using a simple YAML configuration.
  • 🔄 Transformations: Apply custom transformations to raw features to derive new features.
  • 🔗 Dependency Management: Automatically handle dependencies between features.
  • ✔️ Pydantic Validation: Ensure data types and values conform to expected formats.
  • 🛡️ Fail-Fast with Beartype: Catch type-related errors instantly during development, ensuring your transformations are robust.
  • 🚀 Scalability: Designed to scale from small projects to large machine learning pipelines.
  • 🔧 Hydra Integration: Leverage Hydra for configuration management, enabling flexible and dynamic configuration of transformations.

🛠️ Quick Start

Installation

To install Feature Fabrica, simply run:

pip install feature-fabrica

Defining Features in YAML

Features are defined in a YAML file. Here’s an example:

feature_a:
  description: "Raw feature A"
  data_type: "float32"

feature_b:
  description: "Raw feature B"
  data_type: "float32"

feature_c:
  description: "Derived feature C"
  data_type: "float32"
  dependencies: ["feature_a", "feature_b"]
  transformation:
    sum_fn:
      _target_: feature_fabrica.transform.SumReduce
      iterable: ["feature_a", "feature_b"]
    scale_feature:
      _target_: feature_fabrica.transform.ScaleFeature
      factor: 0.5

Creating and Using Transformations

You can define custom transformations by subclassing the Transformation class:

from typing import Union
import numpy as np
from beartype import beartype
from numpy.typing import NDArray
from feature_fabrica.transform import Transformation
from feature_fabrica.transform.utils import NumericArray, NumericValue


class ScaleFeature(Transformation):
    def __init__(self, factor: float):
        super().__init__()
        self.factor = factor

    @beartype
    def execute(self, data: NumericArray | NumericValue) -> NumericArray | NumericValue:
        return np.multiply(data, self.factor)

Compiling and Executing Features

To compile and execute features:

import numpy as np
from feature_fabrica.core import FeatureManager

data = {
    "feature_a": np.array([10.0], dtype=np.float32),
    "feature_b": np.array([20.0], dtype=np.float32),
}
feature_manager = FeatureManager(
    config_path="../examples", config_name="basic_features"
)
results = feature_manager.compute_features(data)
print(results["feature_c"])  # 0.5 * (10 + 20) = 15.0
print(results.feature_c)  # 0.5 * (10 + 20) = 15.0

Visualize Features and Dependencies

Track & trace Transformation Chains

import numpy as np
from feature_fabrica.core import FeatureManager

data = {
    "feature_a": np.array([10.0], dtype=np.float32),
    "feature_b": np.array([20.0], dtype=np.float32),
}
feature_manager = FeatureManager(
    config_path="../examples", config_name="basic_features"
)
results = feature_manager.compute_features(data)
print(feature_manager.features.feature_c.get_transformation_chain())
# Transformation Chain: (Transformation: sum_fn, Value: 30.0 Time taken: 9.5367431640625e-07 seconds) -> (Transformation: scale_feature, Value: 15.0, Time taken:  9.5367431640625e-07 seconds)

Visualize Dependencies

from feature_fabrica.core import FeatureManager

feature_manager = FeatureManager(
    config_path="../examples", config_name="basic_features"
)
feature_manager.get_visual_dependency_graph()

image.png

Contributing

We welcome contributions to Feature Fabrica! If you have ideas for new features, improvements, or if you'd like to report issues, feel free to open a pull request or an issue on GitHub.

How to Contribute

  1. Fork the repository to your own GitHub account.
  2. Clone your fork locally.
  3. Create a new branch for your feature or fix.
  4. Commit your changes with a clear and concise message.
  5. Push to the branch.
  6. Open a pull request from your fork to the original repository.

We look forward to your contributions! 😄

Metadata

Release files for feature-fabrica 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for feature-fabrica 1.3.1
File Size Uploaded Provenance Actions
feature_fabrica-1.3.1.tar.gz 21.5 kB Without provenance Details for feature_fabrica-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for feature-fabrica 1.3.1
File Interpreter ABI Platform Actions
feature_fabrica-1.3.1-py3-none-any.whl Python 3 none any Details for feature_fabrica-1.3.1-py3-none-any.whl

Total release size: 46.9 kB

Release files / feature_fabrica-1.3.1.tar.gz

Download URL feature_fabrica-1.3.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fc33f7ecfd00e318c94acd52aab6cc7ebe505f62d7093922e622293de8c6d817
BLAKE2b-256 checksum
How to use checksums
cde9e0326a0198014801fc0388f3b367cd7eb52eb5106f53d65573b4cff2d39c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / feature_fabrica-1.3.1-py3-none-any.whl

Download URL feature_fabrica-1.3.1-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
575271d1b25a345602414cfe11cc3fddab2c857f62330899a64325c4ef918458
BLAKE2b-256 checksum
How to use checksums
9a32e2e697191e40d0f605bf1b4eea2781177af9246bdf4d91cc027f6819fa0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Security for feature-fabrica 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page