Table 3: Examples of common strategies employed by CAAFE for feature extension. The full code and comments are automatically generated based on the user-provided dataset descriptions. CAAFE combines features, creates ordinal versions of numerical features through binning, performs string transformations, removes superfluous features, and even recovers from errors when generating invalid code.
Description	Generated code
Combination
Example from the Kaggle Kidney Stone dataset.	# Usefulness: Fever and rhinorrhea are two of the most common symptoms of respiratory infections, including GAS pharyngitis. This feature captures their co-occurrence.
# Input samples: 'temperature': [38.0, 39.0, 39.5], 'rhinorrhea': [0.0, 0.0, 0.0]
df['fever_and_rhinorrhea'] = ((df['temperature'] >= 38.0) & (df['rhinorrhea'] > 0)). astype(int)
Binning
Example from the Kaggle Spaceship Titanic dataset.	# Feature: AgeGroup (categorizes passengers into age groups)
# Usefulness: Different age groups might have different likelihoods of being transported.
# Input samples: 'Age': [30.0, 0.0, 37.0]
bins = [0, 12, 18, 35, 60, 100]
labels = ['Child', 'Teen', 'YoungAdult', 'Adult', 'Senior']
df['AgeGroup'] = pd.cut(df['Age'], bins=bins, labels=labels)
df['AgeGroup'] = df['AgeGroup'].astype('category')
String transformation
Example from the Kaggle Spaceship Titanic dataset.	# Feature: Deck
# Usefulness: The deck information can help identify patterns in the location of cabins associated with transported passengers.
# Input samples: 'Cabin': ['F/356/S', 'G/86/P', 'C/37/P']
df['Deck'] = df['Cabin'].apply( lambda x: x[0] if isinstance(x, str) else 'Unknown')
# Feature: CabinSide
# Usefulness: The side of the cabin can help identify patterns in the location of cabins associated with transported passengers.
# Input samples: 'Cabin': ['F/356/S', 'G/86/P', 'C/37/P']
df['CabinSide'] = df['Cabin'].apply( lambda x: x.split('/')[-1] if isinstance(x, str) else 'Unknown')
Removing features
Example from the Balance Scale dataset.	# Drop original columns
# Explanation: The original columns 'left-weight', 'left-distance', 'right-weight', and 'right-distance' can be dropped as the newly created columns 'leftmoment', 'rightMoment', and 'moment_diffrence' capture the relevant information for predicting the 'class'.
df.drop(columns=['left-weight', 'left-distance', 'right-weight', 'right-distance'], inplace=True)
# No more additional columns needed
Error Recovery
Example from the Kaggle Health Insurance dataset. The code execution failed because missing values were not considered in the dataframe. In the next iteration code is suggested that can handle missing values.	# Feature: Age_diffrence
# Usefulness: Age difference between upper and lower age can be useful in determining the likelihood of a person applying for a policy.
# Input samples: 'Upper_Age': ['C33', 'C2', 'C3'], 'Lower_Age': ['Owned', 'Rented', 'Rented']
df['Age_diffrence'] = df['Upper_Age'].str.extract('/(\d+)', astype(int) - df['Lower_Age'].str.extract('/(\d+)', astype(int))
Feedback: failed with error: cannot convert float NaN to integer.
# Feature: Age_diffrence
# Usefulness: Age difference between upper and lower age can be useful in determining the likelihood of a person applying for a policy.
# Input samples: 'Upper_Age': ['C33', 'C2', 'C3'], 'Lower_Age': ['Owned', 'Rented', 'Rented']
df['Age_diffrence'] = df['Upper_Age'].str.extract('/(\d+)', astype(float).fillna(0) - df['Lower_Age'].str.extract('/(\d+)', astype(float).fillna(0))