UpcaseM
UpcaseM

Reputation: 37

How to use Featuretools to create features for a single table with no immediate features?

I used the answer from @willk, but it pops up an error. see willk's answer here. willk's anser I cannot make a comment in his answer because I don't have enough reputation(Over 50).

So my question is how to make the code below work? Or please provide a solution that use featuretools to apply auto feature engineering for a single table(use iris as an example) and no immediate features on which to normalize (make a new table from an existing table).

from sklearn.datasets import load_iris
import pandas as pd 
import featuretools as ft

# Load data and put into dataframe
iris = load_iris()
df = pd.DataFrame(iris.data, columns = iris.feature_names)
df['species'] = iris.target
df['species'] = df['species'].map({0: 'setosa', 1: 'versicolor', 2: 'virginica'})

# Make an entityset and add the entity
es = ft.EntitySet(id = 'iris')
es.entity_from_dataframe(entity_id = 'data', dataframe = df, 
                     make_index = True, index = 'index')

# Run deep feature synthesis with transformation primitives
feature_matrix, feature_defs = ft.dfs(entityset = es, target_entity = 'data',
                                  trans_primitives = ['add', 'multiply'])
feature_matrix.head()

ValueError: ('Unknown transform primitive add. ', 'Call ft.primitives.list_primitives() to get', ' a list of available primitives')

Upvotes: 2

Views: 1385

Answers (1)

Max Kanter
Max Kanter

Reputation: 2014

The 0.6.1 release of featuretools changed some of the primitive names. The following code should run for you

from sklearn.datasets import load_iris
import pandas as pd 
import featuretools as ft

# Load data and put into dataframe
iris = load_iris()
df = pd.DataFrame(iris.data, columns = iris.feature_names)
df['species'] = iris.target
df['species'] = df['species'].map({0: 'setosa', 1: 'versicolor', 2: 'virginica'})

# Make an entityset and add the entity
es = ft.EntitySet(id = 'iris')
es.entity_from_dataframe(entity_id = 'data', dataframe = df, 
                     make_index = True, index = 'index')

# Run deep feature synthesis with transformation primitives
feature_matrix, feature_defs = ft.dfs(entityset = es, target_entity = 'data',
                                  trans_primitives = ['add_numeric', 'multiply_numeric'])
feature_matrix.head()

Upvotes: 4

Related Questions