Skip to content

base

logger = logging.getLogger(__name__) module-attribute

Splitter

Bases: ABC

Abstract base class for dataset splitters.

Implementations should split an :class:InteractionMatrix into two parts according to a splitting condition (for example, by timestamp).

Source code in src/streamsight/settings/splitters/base.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Splitter(ABC):
    """Abstract base class for dataset splitters.

    Implementations should split an :class:`InteractionMatrix` into two
    parts according to a splitting condition (for example, by timestamp).
    """

    def __init__(self) -> None:
        pass

    @property
    def name(self) -> str:
        """Return the class name of the splitter.

        Returns:
            The splitter class name.
        """
        return self.__class__.__name__

    @property
    def identifier(self) -> str:
        """Return a string identifier including the splitter's parameters.

        The identifier includes the class name and a comma-separated list of
        attribute name/value pairs from `self.__dict__`.

        Returns:
            Identifier string like `Name(k1=v1,k2=v2)`.
        """

        paramstring = ",".join((f"{k}={v}" for k, v in self.__dict__.items()))
        return self.name + f"({paramstring})"

    @abstractmethod
    def split(self, data: InteractionMatrix) -> tuple[InteractionMatrix, InteractionMatrix]:
        """Split an interaction matrix into two parts.

        Args:
            data (InteractionMatrix): The interaction dataset to split.

        Returns:
            A pair of `InteractionMatrix` objects representing the two parts.

        Raises:
            NotImplementedError: If the concrete splitter does not implement this method.
        """

        raise NotImplementedError(f"{self.name} must implement the _split method.")

name property

Return the class name of the splitter.

Returns:

Type Description
str

The splitter class name.

identifier property

Return a string identifier including the splitter's parameters.

The identifier includes the class name and a comma-separated list of attribute name/value pairs from self.__dict__.

Returns:

Type Description
str

Identifier string like Name(k1=v1,k2=v2).

split(data) abstractmethod

Split an interaction matrix into two parts.

Parameters:

Name Type Description Default
data InteractionMatrix

The interaction dataset to split.

required

Returns:

Type Description
tuple[InteractionMatrix, InteractionMatrix]

A pair of InteractionMatrix objects representing the two parts.

Raises:

Type Description
NotImplementedError

If the concrete splitter does not implement this method.

Source code in src/streamsight/settings/splitters/base.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@abstractmethod
def split(self, data: InteractionMatrix) -> tuple[InteractionMatrix, InteractionMatrix]:
    """Split an interaction matrix into two parts.

    Args:
        data (InteractionMatrix): The interaction dataset to split.

    Returns:
        A pair of `InteractionMatrix` objects representing the two parts.

    Raises:
        NotImplementedError: If the concrete splitter does not implement this method.
    """

    raise NotImplementedError(f"{self.name} must implement the _split method.")