Skip to content

Add TargetEncoder for scikit-learn #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions stubs/sklearn/preprocessing/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ from ._label import (
label_binarize as label_binarize,
)
from ._polynomial import PolynomialFeatures as PolynomialFeatures, SplineTransformer as SplineTransformer
from ._target_encoder import TargetEncoder as TargetEncoder

__all__ = [
"Binarizer",
Expand All @@ -36,26 +37,27 @@ __all__ = [
"KernelCenterer",
"LabelBinarizer",
"LabelEncoder",
"MultiLabelBinarizer",
"MinMaxScaler",
"MaxAbsScaler",
"QuantileTransformer",
"MinMaxScaler",
"MultiLabelBinarizer",
"Normalizer",
"OneHotEncoder",
"OrdinalEncoder",
"PolynomialFeatures",
"PowerTransformer",
"QuantileTransformer",
"RobustScaler",
"SplineTransformer",
"StandardScaler",
"TargetEncoder",
"add_dummy_feature",
"PolynomialFeatures",
"binarize",
"normalize",
"scale",
"robust_scale",
"label_binarize",
"maxabs_scale",
"minmax_scale",
"label_binarize",
"quantile_transform",
"normalize",
"power_transform",
"quantile_transform",
"robust_scale",
"scale",
]
34 changes: 34 additions & 0 deletions stubs/sklearn/preprocessing/_target_encoder.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import ClassVar, Literal
from typing_extensions import Self

from numpy import ndarray

from .._typing import ArrayLike, Int, MatrixLike
from ..base import OneToOneFeatureMixin
from ._encoders import _BaseEncoder

class TargetEncoder(OneToOneFeatureMixin, _BaseEncoder):
encodings_: list[ndarray]
categories_: list[ndarray]
target_type_: str
target_mean_: float
n_features_in_: int
feature_names_in_: ndarray
classes_: ndarray | None

_parameter_constraints: ClassVar[dict] = ...

def __init__(
self,
categories: list[ArrayLike] | Literal["auto"] = "auto",
target_type: Literal["auto", "continuous", "binary", "multiclass"] = "auto",
smooth: Literal["auto"] | float = "auto",
cv: int = 5,
shuffle: bool = True,
random_state: Int | None = None,
) -> None: ...
def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ...
def fit_transform(self, X: MatrixLike, y: ArrayLike) -> ndarray: ...
def transform(self, X: MatrixLike) -> ndarray: ...
def get_feature_names_out(self, input_features: ArrayLike | None = None) -> ndarray: ...
def __sklearn_tags__(self) -> dict: ...