Skip to main content

featureclass

Feature engineering library that helps you keep track of feature dependencies, documentation and schema

Installation

Using pip

pip install featureclass

Motivation

This library helps define a featureclass.
featureclass is inspired by dataclass, and is meant to provide alternative way to define features engineering classes.

I have noticed that the below code is pretty common when doing feature engineering:

from statistics import variance
from math import sqrt
class MyFeatures:
    def calc_all(self, datapoint):
        out = {}
        out['var'] = self.calc_var(datapoint),
        out['stdev'] = self.calc_std(out['var'])
        return out
        
    def calc_var(self, data) -> float:
        return variance(data)

    def calc_stdev(self, var) -> float:
        return sqrt(var)

Some things were missing for me from this type of implementation:

  1. Implicit dependencies between features
  2. No simple schema
  3. No documentation for features
  4. Duplicate declaration of the same feature - once as a function and one as a dict key

This is why I created this library.
I turned the above code into this:

from featureclass import feature, featureclass, feature_names, feature_annotations, asdict, as_dataclass
from statistics import variance
from math import sqrt

@featureclass
class MyFeatures:
    def __init__(self, datapoint):
        self.datapoint = datapoint
    
    @feature()
    def var(self) -> float:
        """Calc variance"""
        return variance(self.datapoint)

    @feature()
    def stdev(self) -> float:
        """Calc stdev"""
        return sqrt(self.var)

print(feature_names(MyFeatures)) # ('var', 'stdev')
print(feature_annotations(MyFeatures)) # {'var': float, 'stdev': float}
print(asdict(MyFeatures([1,2,3,4,5]))) # {'var': 2.5, 'stdev': 1.5811388300841898}
print(as_dataclass(MyFeatures([1,2,3,4,5]))) # MyFeatures(stdev=1.5811388300841898, var=2.5)

The feature decorator is using cached_property to cache the feature calculation,
making sure that each feature is calculated once per datapoint

Metadata

Release files for featureclass 0.3.0

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

Source distribution (sdist)

Source distribution for featureclass 0.3.0
File Size Uploaded Provenance Actions
featureclass-0.3.0.tar.gz 8.4 kB Without provenance Details for featureclass-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for featureclass 0.3.0
File Interpreter ABI Platform Actions
featureclass-0.3.0-py3-none-any.whl Python 3 none any Details for featureclass-0.3.0-py3-none-any.whl

Total release size: 17.4 kB

Release files / featureclass-0.3.0.tar.gz

Download URL featureclass-0.3.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ef8f586622aae156eda6d79d86187cac310ffe3d5c0cfbbb12ef3d9ae1ae7bc5
BLAKE2b-256 checksum
How to use checksums
a091abb7c789185f0650129117afb189a893b268f1d1b3663a53d71c0d022438
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1025-azure

Release files / featureclass-0.3.0-py3-none-any.whl

Download URL featureclass-0.3.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7dadbb0620bd87c573d6988f7456af40ec5a4938fcc1630d7453a317ca8ec09
BLAKE2b-256 checksum
How to use checksums
ee903530f795f51134bd9dcf29c987676deac1a8211521c8444a43af5ef62271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1025-azure

Security for featureclass 0.3.0

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