Skip to content

Support typing #16705

@bryant1410

Description

@bryant1410

Describe the workflow you want to enable

Support Python typing, which is available in Python 3.5+, compatible with scikit-learn. This can enable tools to automatically get the estimator arg types (e.g., linters), for example. And it's a Python standard now.

Describe your proposed solution

For example, SVC could be like this:

def __init__(
    self,
     C: float = 1.0,
     kernel: Union[Callable[[np.ndarray, np.ndarray], np.ndarray],
                   Literal["linear", "poly", "rbf", "sigmoid", "precomputed"]] = "rbf",
     degree: int = 3,
     gamma: Union[float, Literal["scale", "auto"]] = "scale",
     coef0: float = 0.0,
     shrinking: bool = True,
     probability: bool = False,
     tol: float = 1e-3,
     cache_size: int = 200,
     class_weight: Optional[Union[Mapping[int, float], Literal["balanced"]]] = None,
     verbose: bool = False,
     max_iter: int = -1,
     decision_function_shape: Literal["ovo", "ovr"] = "ovr",
     break_ties: bool = False,
     random_state: Optional[Union[int, RandomState]] = None,
 ) -> None:

Describe alternatives you've considered, if relevant

An alternative is to keep the types just in the docstrings. However, is hard for tools to parse the arg types.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions