Skip to content

utils

ClientTabPFNClassifier

Bases: TabPFNClassifier

get_params

get_params(deep: bool = True) -> dict[str, Any]

Return parameters for this estimator.

predict

predict(X)

Predict class labels for samples in X.

Parameters:

Name Type Description Default
X

The input samples.

required

Returns:

Type Description

The predicted class labels.

predict_proba

predict_proba(X)

Predict class probabilities for X.

Parameters:

Name Type Description Default
X

The input samples.

required

Returns:

Type Description

The class probabilities of the input samples.

ClientTabPFNRegressor

Bases: TabPFNRegressor

get_params

get_params(deep: bool = True) -> dict[str, Any]

Return parameters for this estimator.

predict

predict(X, output_type=None, **kwargs)

Predict target values for X.

Parameters

X : array-like of shape (n_samples, n_features) The input samples.

str, default=None

Type of output to return. Options are: - None: Default prediction (mean) - "full": Return distribution dictionary with criterion object - Other values are passed to the parent predict

**kwargs : Additional keyword arguments Passed to the parent predict method.

Returns:

y : array-like of shape (n_samples,) or dict The predicted values or the full distribution output dictionary.

get_device

get_device(device: str | None = 'auto') -> str

Determine the appropriate device for computation.

This function implements automatic device selection, defaulting to CUDA if available, otherwise falling back to CPU.

Parameters:

Name Type Description Default
device str | None

Device specification, options are: - "auto": Automatically use CUDA if available, otherwise CPU - "cpu": Force CPU usage - "cuda": Force CUDA usage (raises error if not available) - None: Same as "auto"

'auto'

Returns:

Name Type Description
str str

The resolved device string ("cpu" or "cuda")

Raises:

Type Description
RuntimeError

If "cuda" is explicitly requested but not available

get_tabpfn_models

get_tabpfn_models() -> tuple[type, type]

Get TabPFN models with fallback between different versions.

Attempts to import TabPFN models in the following order: 1. Standard TabPFN package (if USE_TABPFN_LOCAL is True) 2. TabPFN client

Returns:

Type Description
tuple[type, type]

tuple[type, type]: A tuple containing (TabPFNClassifier, TabPFNRegressor) classes

Raises:

Type Description
ImportError

If none of the TabPFN implementations could be imported

infer_categorical_features

infer_categorical_features(
    X: ndarray,
    categorical_features: list[int] | None = None,
) -> list[int]

Infer the categorical features from the input data.

Features are identified as categorical if any of these conditions are met: 1. The feature index is in the provided categorical_features list AND has few unique values 2. The feature has few unique values compared to the dataset size 3. The feature has string/object/category data type (pandas DataFrame) 4. The feature contains string values (numpy array)

Parameters:

Name Type Description Default
X ndarray or DataFrame

The input data.

required
categorical_features list[int]

Initial list of categorical feature indices. If None, will start with an empty list.

None

Returns:

Type Description
list[int]

list[int]: The indices of the categorical features.

is_tabpfn

is_tabpfn(estimator: Any) -> bool

Check if an estimator is a TabPFN model.

product_dict

product_dict(
    d: dict[str, list[T]]
) -> Iterator[dict[str, T]]

Cartesian product of a dictionary of lists.

This function takes a dictionary where each value is a list, and returns an iterator over dictionaries where each key is mapped to one element from the corresponding list.

Parameters:

Name Type Description Default
d dict[str, list[T]]

A dictionary mapping keys to lists of values.

required

Returns:

Type Description
dict[str, T]

An iterator over dictionaries, each being one element of the cartesian

dict[str, T]

product of the input dictionary.

Example

list(product_dict({'a': [1, 2], 'b': ['x', 'y']})) [{'a': 1, 'b': 'x'}, {'a': 1, 'b': 'y'}, {'a': 2, 'b': 'x'}, {'a': 2, 'b': 'y'}]

softmax

softmax(logits: NDArray) -> NDArray

Apply softmax function to convert logits to probabilities.

Parameters:

Name Type Description Default
logits NDArray

Input logits array of shape (n_samples, n_classes) or (n_classes,)

required

Returns:

Type Description
NDArray

Probabilities where values sum to 1 across the last dimension