Skip to content

FinetunedTabPFNClassifier drops Pandas feature names if X_val is used #872

@jakewatson91

Description

@jakewatson91

Describe the bug

Error: UserWarning: X does not have valid feature names, but TabPFNClassifier was fitted with feature names

It seems that calling .fit() with X_val and y_val converts the training data to tensors early, which deletes the Pandas feature names.

If X_val is omitted, the model remembers the feature names.

If X_val is included, it forgets them. Calling .predict_proba(X_test) with a DataFrame later throws a UserWarning about missing feature names.

The Workaround:
Cast test data to numpy (X_test.to_numpy()) during inference.

With X_val...
finetuned_clf.fit(X_train, y_train, X_val=X_val, y_val=y_val)
finetuned_clf.predict_proba(X_test.to_numpy())

Without...
finetuned_clf.fit(X_train, y_train)
finetuned_clf.predict_proba(X_test)

Steps/Code to Reproduce

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from tabpfn.finetuning.finetuned_classifier import FinetunedTabPFNClassifier

# 1. Create dummy Pandas DataFrame with feature names
X, y = make_classification(n_samples=500, n_features=10, random_state=42)
X_df = pd.DataFrame(X, columns=[f"feature_{i}" for i in range(10)])

X_train, X_temp, y_train, y_temp = train_test_split(X_df, y, test_size=0.4, random_state=42)
X_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5, random_state=42)

clf = FinetunedTabPFNClassifier(
    device="cuda",
    epochs=2,
    n_estimators_finetune=2, 
    n_estimators_final_inference=2
)

# 2. Fit WITH validation sets
clf.fit(X_train, y_train, X_val=X_val, y_val=y_val)

# 3. Predict with a DataFrame (Triggers Warning)
preds = clf.predict_proba(X_test)```

### Expected Results

Warning is thrown, but does not stop the run.

### Actual Results

`Error: UserWarning: X does not have valid feature names, but TabPFNClassifier was fitted with feature names`


### Versions

```shell
Collecting system and dependency information...
PyTorch version: 2.6.0+cu124
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.11.15 (main, Mar 11 2026, 17:20:07) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-139-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA A100-SXM4-80GB
Nvidia driver version: 570.133.20
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Byte Order:                           Little Endian
Address sizes:                        48 bits physical, 48 bits virtual
CPU(s):                               64
On-line CPU(s) list:                  0-63
Thread(s) per core:                   1
Core(s) per socket:                   32
Socket(s):                            2
NUMA node(s):                         8
Vendor ID:                            AuthenticAMD
CPU family:                           25
Model:                                1
Model name:                           AMD EPYC 7543 32-Core Processor
Stepping:                             1
CPU MHz:                              2794.685
BogoMIPS:                             5589.37
Virtualization:                       AMD-V
L1d cache:                            2 MiB
L1i cache:                            2 MiB
L2 cache:                             32 MiB
L3 cache:                             512 MiB
NUMA node0 CPU(s):                    0-7
NUMA node1 CPU(s):                    8-15
NUMA node2 CPU(s):                    16-23
NUMA node3 CPU(s):                    24-31
NUMA node4 CPU(s):                    32-39
NUMA node5 CPU(s):                    40-47
NUMA node6 CPU(s):                    48-55
NUMA node7 CPU(s):                    56-63
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Mitigation; safe RET
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; IBPB conditional; IBRS_FW; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 invpcid_single hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold v_vmsave_vmload vgif v_spec_ctrl umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca

Dependency Versions:
--------------------
tabpfn: 7.0.1
torch: 2.6.0+cu124
numpy: 2.1.3
scipy: 1.16.3
pandas: 2.3.3
scikit-learn: 1.7.2
typing_extensions: 4.15.0
einops: 0.8.2
huggingface-hub: 0.36.2

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