Skip to main content

A library for data science teams to avoid code duplication in common tasks involving scikit-learn transformers and estimators.

Project description

Data Science Utils

A toolkit for day-to-day DS tasks such as using custom transformers or estimators.

Found a bug or have a feature request? Open an issue!

Usage

First, import the library:

import pier_ds_utils as ds

Transformers

CustomDiscreteCategorizer

discrete_categorizer = ds.transformer.CustomDiscreteCategorizer(
        column="input_col_name",
        categories=[["my_category_value_1", "my_category_value_2"], ["my_category_value_3"]],
        labels=["label_1", "label_2"],
        default_value="a-default-value",
        output_column="output_col_name",
    )

CustomIntervalCategorizer

interval_categorizer = ds.transformer.CustomIntervalCategorizer(
    column="price",
    intervals=[(6700000, sys.maxsize)],
    labels=["gt_67k"],
    default_value="lt_67k",
    output_column="cat_price",
)

CustomIntervalCategorizerByCategory

interval_categorizer_by_category = ds.transformer.CustomIntervalCategorizerByCategory(
    category_column: "category",
    interval_categorizers: {
        "category_1": CustomIntervalCategorizer(
            column="price",
            intervals=[(6700000, sys.maxsize)],
            labels=["gt_67k"],
            default_value="lt_67k",
            output_column="cat_price",
        ),
        "category_2": CustomIntervalCategorizer(
            column="price",
            intervals=[(0, 1000000)],
            labels=["lt_1M"],
            default_value="gt_1M",
            output_column="cat_price",
        ),
    },
    output_column = "cat_price",
)

LogTransformer

log_transformer = ds.transformer.LogTransformer()

BoundariesTransformer

boundaries_transformer = ds.transformer.BoundariesTransformer(
    column="price",
    lower_bound=0,
    upper_bound=1000000,
    output_column="price_bounded",
)

Estimators

glm_wrapper = ds.estimator.GLMWrapper(...)
predict_proba_selector = ds.estimator.PredictProbaSelector(...)

Predictors

predictor = ds.predictor.StaticGLM(...)

Example usage:

from pier_ds_utils.predictor import StaticGLM
import pandas as pd

glm = StaticGLM(
    coefficients_map={"feature1": 0.5, "feature2": 1.5},  # required
    constant=2.0,  # optional
    os_factor=1.0,  # optional
)

df = pd.DataFrame({"feature1": [1, 2], "feature2": [3, 4]})

# The predict is equivalent to:
# y = (0.5 * feature1 + 1.5 * feature2 + constant) * os_factor
print(glm.predict(df))  # Output: [7. 9.]

Installation

pip install pier-ds-utils

# or

poetry add pier-ds-utils

For a specific version:

pip install pier-ds-utils@_version_

# or

poetry add pier-ds-utils@_version_

Contributing

Contributions are welcome! Please read the contributing guidelines first.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pier_ds_utils-0.5.0a3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pier_ds_utils-0.5.0a3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pier_ds_utils-0.5.0a3.tar.gz.

File metadata

  • Download URL: pier_ds_utils-0.5.0a3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for pier_ds_utils-0.5.0a3.tar.gz
Algorithm Hash digest
SHA256 3b8aeb6c6f7e21fddfff7ad6292a23994fd6ce3943ebea9908826e9a7d5ab369
MD5 1c52fc8af32568663cbd28b801c79b7a
BLAKE2b-256 1bfab0cb23578a2b2329c3e0d796b2ee88f72563c6a31a14684eba1ad081428b

See more details on using hashes here.

File details

Details for the file pier_ds_utils-0.5.0a3-py3-none-any.whl.

File metadata

  • Download URL: pier_ds_utils-0.5.0a3-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for pier_ds_utils-0.5.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 aff7940fb14ecc62c91a74c17f9932e9679aa40dd61981ff4f61c6cc2abcfafc
MD5 a97977c8abf31486444adcf40a0fb24d
BLAKE2b-256 288a3f104e780cf6ab3f521db023e1fdc7525a17ee59181c07294e997bc7ccb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page