doubt.models.model

Protocol class for estimators.

 1"""Protocol class for estimators."""
 2
 3from typing import Protocol, Tuple, Union
 4
 5import numpy as np
 6
 7
 8class Model(Protocol):
 9    def __init__(self, *args, **kwargs):
10        ...
11
12    def predict(
13        self, X: np.ndarray, **kwargs
14    ) -> Tuple[Union[float, np.ndarray], np.ndarray]:
15        ...
16
17    def fit(self, X: np.ndarray, y: np.ndarray, **kwargs):
18        ...
19
20    def __call__(
21        self, X: np.ndarray, **kwargs
22    ) -> Tuple[Union[float, np.ndarray], np.ndarray]:
23        ...
class Model(typing.Protocol):
 9class Model(Protocol):
10    def __init__(self, *args, **kwargs):
11        ...
12
13    def predict(
14        self, X: np.ndarray, **kwargs
15    ) -> Tuple[Union[float, np.ndarray], np.ndarray]:
16        ...
17
18    def fit(self, X: np.ndarray, y: np.ndarray, **kwargs):
19        ...
20
21    def __call__(
22        self, X: np.ndarray, **kwargs
23    ) -> Tuple[Union[float, np.ndarray], np.ndarray]:
24        ...

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
Model(*args, **kwargs)
10    def __init__(self, *args, **kwargs):
11        ...
def predict( self, X: numpy.ndarray, **kwargs) -> Tuple[Union[float, numpy.ndarray], numpy.ndarray]:
13    def predict(
14        self, X: np.ndarray, **kwargs
15    ) -> Tuple[Union[float, np.ndarray], np.ndarray]:
16        ...
def fit(self, X: numpy.ndarray, y: numpy.ndarray, **kwargs):
18    def fit(self, X: np.ndarray, y: np.ndarray, **kwargs):
19        ...