Skip to main content

Featuretools Transformer for Scikit-Learn Pipeline use.

Project description

featuretools-sklearn-transformer

Tests Coverage Status PyPI version

Featuretools' DFS as a scikit-learn transformer

Install

pip install featuretools_sklearn_transformer

Use

To use the transformer in a pipeline, initialize an instance of the transformer by passing in the parameters you would like to use for calculating features. To fit the model and generate features for the training data, pass in an entityset or list of dataframes and relationships containing only the relevant training data as the X input, along with the training targets as the y input. To generate a feature matrix from test data, pass in an entityset containing only the relevant test data as the X input.

The input supplied for X can take several formats:

  • To use a Featuretools EntitySet without cutoff times, simply pass in the EntitySet
  • To use a Featuretools EntitySet with a cutoff times DataFrame, pass in a tuple of the form (EntitySet, cutoff_time_df)
  • To use a list DataFrames and Relationships without cutoff times, pass a tuple of the form (dataframes, relationships)
  • To use a list of DataFrames and Relationships with a cutoff times DataFrame, pass a tuple of the form ((dataframes, relationships), cutoff_time_df)

Note that because this transformer requires a Featuretools EntitySet or dataframes and relationships as input, it does not currently work with certain methods such as sklearn.model_selection.cross_val_score or sklearn.model_selection.GridSearchCV which expect the X values to be an iterable which can be split by the method.

The example below shows how to use the transformer with an EntitySet, both with and without a cutoff time DataFrame.

import featuretools as ft
import pandas as pd

from featuretools.wrappers import DFSTransformer
from sklearn.pipeline import Pipeline
from sklearn.ensemble import ExtraTreesClassifier

# Get example data
train_es = ft.demo.load_mock_customer(return_entityset=True, n_customers=3)
test_es = ft.demo.load_mock_customer(return_entityset=True, n_customers=2)
y = [True, False, True]

# Build pipeline
pipeline = Pipeline(steps=[
    ('ft', DFSTransformer(target_dataframe_name="customers",
                          max_features=2)),
    ('et', ExtraTreesClassifier(n_estimators=100))
])

# Fit and predict
pipeline.fit(X=train_es, y=y) # fit on customers in training entityset
pipeline.predict_proba(test_es) # predict probability of each class on test entityset
pipeline.predict(test_es) # predict on test entityset

# Same as above, but using cutoff times
train_ct = pd.DataFrame()
train_ct['customer_id'] = [1, 2, 3]
train_ct['time'] = pd.to_datetime(['2014-1-1 04:00',
                                   '2014-1-2 17:20',
                                   '2014-1-4 09:53'])

pipeline.fit(X=(train_es, train_ct), y=y)

test_ct = pd.DataFrame()
test_ct['customer_id'] = [1, 2]
test_ct['time'] = pd.to_datetime(['2014-1-4 13:48',
                                  '2014-1-5 15:32'])
pipeline.predict_proba((test_es, test_ct))
pipeline.predict((test_es, test_ct))

Built at Alteryx Innovation Labs

Alteryx Innovation Labs

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

Built Distribution

File details

Details for the file featuretools_sklearn_transformer-1.0.0.tar.gz.

File metadata

  • Download URL: featuretools_sklearn_transformer-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.13

File hashes

Hashes for featuretools_sklearn_transformer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3cdb677dbecc82d1f4cf430fe363642c8bd37636773b562f227c1e53a7ccdbae
MD5 864c7b391a973b5047ec0b606e57fe78
BLAKE2b-256 39f5c45406f708a3453cacf15b908b778b47ec23436b9a9c4d5bc110073525b9

See more details on using hashes here.

File details

Details for the file featuretools_sklearn_transformer-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: featuretools_sklearn_transformer-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.13

File hashes

Hashes for featuretools_sklearn_transformer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e630e1d2e3c35aa2d8d941fe330cdc54a5e32c86d4ea1381d57d4cef8f721a5
MD5 e434bf50bebbdb4a6976ab7e5926e087
BLAKE2b-256 05f1f10d2ae89dfbdab74ee9d073629583acf2aafab6b3fc257939c2bca7f6ad

See more details on using hashes here.

Supported by

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