ClassifierAsRegressor ¶
Bases: RegressorMixin
Wrapper class to use a classifier as a regressor.
This class takes a classifier estimator and converts it into a regressor by encoding the target labels and treating the regression problem as a classification task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
estimator |
object Classifier estimator to be used as a regressor. |
required |
Attributes:
Name | Type | Description |
---|---|---|
label_encoder_ |
LabelEncoder Label encoder used to transform target regression labels to classes. |
|
y_train_ |
array-like of shape (n_samples,) Transformed target labels used for training. |
|
categorical_features |
list List of categorical feature indices. |
>>> from sklearn.datasets import load_diabetes
>>> from sklearn.model_selection import train_test_split
>>> from tabpfn.scripts.estimator import ManyClassClassifier, TabPFNClassifier, ClassifierAsRegressor
>>> x, y = load_diabetes(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, n_estimators=10, alphabet_size=clf.max_num_classes_)
>>> reg = ClassifierAsRegressor(clf)
>>> reg.fit(x_train, y_train)
>>> y_pred = reg.predict(x_test)
fit ¶
Fit the classifier as a regressor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
array-like of shape (n_samples, n_features) Training data. |
required | |
y |
array-like of shape (n_samples,) Target labels. |
required |
Returns:
Name | Type | Description |
---|---|---|
self |
object Fitted estimator. |
predict ¶
Predict the target values for the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
array-like of shape (n_samples, n_features) Input data. |
required |
Returns:
Name | Type | Description |
---|---|---|
y_pred |
array-like of shape (n_samples,) Predicted target values. |