NOTICE
The upcoming release of Featuretools 1.0.0 contains several breaking changes. Users are encouraged to test this version prior to release by installing from GitHub:
pip install https://github.com/alteryx/featuretools/archive/woodwork-integration.zip
For details on migrating to the new version, refer to Transitioning to Featuretools Version 1.0. Please report any issues in the Featuretools GitHub repo or by messaging in Alteryx Open Source Slack.
Featuretools is a framework to perform automated feature engineering. It excels at transforming temporal and relational datasets into feature matrices for machine learning.
Below is an example of using Deep Feature Synthesis (DFS) to perform automated feature engineering. In this example, we apply DFS to a multi-table dataset consisting of timestamped customer transactions.
[1]:
import featuretools as ft
[2]:
data = ft.demo.load_mock_customer()
In this toy dataset, there are 3 DataFrames.
customers: unique customers who had sessions
sessions: unique sessions and associated attributes
transactions: list of events in this session
[3]:
customers_df = data["customers"] customers_df
[4]:
sessions_df = data["sessions"] sessions_df.sample(5)
[5]:
transactions_df = data["transactions"] transactions_df.sample(5)
First, we specify a dictionary with all the DataFrames in our dataset. The DataFrames are passed in with their index column and time index column if one exists for the DataFrame.
[6]:
dataframes = { "customers" : (customers_df, "customer_id"), "sessions" : (sessions_df, "session_id", "session_start"), "transactions" : (transactions_df, "transaction_id", "transaction_time") }
Second, we specify how the DataFrames are related. When two DataFrames have a one-to-many relationship, we call the “one” DataFrame, the “parent DataFrame”. A relationship between a parent and child is defined like this:
(parent_dataframe, parent_column, child_dataframe, child_column)
In this dataset we have two relationships
[7]:
relationships = [("sessions", "session_id", "transactions", "session_id"), ("customers", "customer_id", "sessions", "customer_id")]
Note
To manage setting up DataFrames and relationships, we recommend using the EntitySet class which offers convenient APIs for managing data like this. See Representing Data with EntitySets for more information.
EntitySet
A minimal input to DFS is a dictionary of DataFrames, a list of relationships, and the name of the target DataFrame whose features we want to calculate. The ouput of DFS is a feature matrix and the corresponding list of feature definitions.
Let’s first create a feature matrix for each customer in the data
[8]:
feature_matrix_customers, features_defs = ft.dfs(dataframes=dataframes, relationships=relationships, target_dataframe_name="customers") feature_matrix_customers
5 rows × 74 columns
We now have dozens of new features to describe a customer’s behavior.
One of the reasons DFS is so powerful is that it can create a feature matrix for any DataFrame in our EntitySet. For example, if we wanted to build features for sessions.
[10]:
feature_matrix_sessions, features_defs = ft.dfs(dataframes=dataframes, relationships=relationships, target_dataframe_name="sessions") feature_matrix_sessions.head(5)
5 rows × 43 columns
In general, Featuretools references generated features through the feature name. In order to make features easier to understand, Featuretools offers two additional tools, featuretools.graph_feature() and featuretools.describe_feature(), to help explain what a feature is and the steps Featuretools took to generate it. Let’s look at this example feature:
featuretools.graph_feature()
featuretools.describe_feature()
[11]:
feature = features_defs[18] feature
<Feature: MODE(transactions.YEAR(transaction_time))>
Feature lineage graphs visually walk through feature generation. Starting from the base data, they show step by step the primitives applied and intermediate features generated to create the final feature.
[12]:
ft.graph_feature(feature)
Featuretools can also automatically generate English sentence descriptions of features. Feature descriptions help to explain what a feature is, and can be further improved by including manually defined custom definitions. See Generating Feature Descriptions for more details on how to customize automatically generated feature descriptions.
[13]:
ft.describe_feature(feature)
'The most frequently occurring value of the year of the "transaction_time" of all instances of "transactions" for each "session_id" in "sessions".'
Learn about Representing Data with EntitySets
Apply automated feature engineering with Deep Feature Synthesis
Explore runnable demos based on real world use cases
Can’t find what you’re looking for? Ask for help
Resources and References
Index
Search Page