Skip to content

TabPFN fails on text with NA #138

Description

@LeoGrin
import pandas as pd
import numpy as np
from tabpfn import TabPFNClassifier
from sklearn.model_selection import train_test_split

# Create a sample dataset with text and NA values
data = {
    'text_feature': ['good product', 'bad service', pd.NA, 'excellent', 'average', pd.NA],
    'numeric_feature': [10, 5, 8, 15, 7, 12],
    'target': [1, 0, 1, 1, 0, 0]
}

# Create DataFrame
df = pd.DataFrame(data)

# Try to use the data directly without handling NA values
X = df[['text_feature', 'numeric_feature']]
y = df['target']

# Split the data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Initialize and try to train TabPFN
classifier = TabPFNClassifier(device='cpu')

# This will fail because TabPFN cannot handle pd.NA or string values directly
try:
    classifier.fit(X_train, y_train)
except Exception as e:
    print("TabPFN failed with error:\n", str(e))

gives

TabPFN failed with error:
 Encoders require their input to be uniformly strings or numbers. Got ['NAType', 'str']

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions