Skip to content

many_class_classifier

ManyClassClassifier

Bases: OutputCodeClassifier

Output-Code multiclass strategy with deciary codebook.

This class extends the original OutputCodeClassifier to support n-ary codebooks (with n=alphabet_size), allowing for handling more classes.

Parameters:

Name Type Description Default
estimator

estimator object An estimator object implementing :term:fit and one of :term:decision_function or :term:predict_proba. The base classifier should be able to handle up to alphabet_size classes.

required
random_state

int, RandomState instance, default=None The generator used to initialize the codebook. Pass an int for reproducible output across multiple function calls. See :term:Glossary <random_state>.

None

Attributes:

Name Type Description
estimators_

list of int(n_classes * code_size) estimators Estimators used for predictions.

classes_

ndarray of shape (n_classes,) Array containing labels.

code_book_

ndarray of shape (n_classes, len(estimators_)) Deciary array containing the code of each class.

Example
>>> from sklearn.datasets import load_iris
>>> from tabpfn.scripts.estimator import ManyClassClassifier, TabPFNClassifier
>>> from sklearn.model_selection import train_test_split
>>> x, y = load_iris(return_X_y=True)
>>> x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=42)
>>> clf = TabPFNClassifier()
>>> clf = ManyClassClassifier(clf, alphabet_size=clf.max_num_classes_)
>>> clf.fit(x_train, y_train)
>>> clf.predict(x_test)

fit

fit(X, y, **fit_params)

Fit underlying estimators.

Parameters:

Name Type Description Default
X

{array-like, sparse matrix} of shape (n_samples, n_features) Data.

required
y

array-like of shape (n_samples,) Multi-class targets.

required
**fit_params

dict Parameters passed to the estimator.fit method of each sub-estimator.

{}

Returns:

Name Type Description
self

object Returns a fitted instance of self.

predict_proba

predict_proba(X)

Predict probabilities using the underlying estimators.

Parameters:

Name Type Description Default
X

{array-like, sparse matrix} of shape (n_samples, n_features) Data.

required

Returns:

Name Type Description
p

ndarray of shape (n_samples, n_classes) Returns the probability of the samples for each class in the model, where classes are ordered as they are in self.classes_.