Passed
Pull Request — master (#110)
by
unknown
01:31
created

BaseExperiment.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
"""Base class for experiment."""
2
3
from skbase.base import BaseObject
4
5
6
class BaseExperiment(BaseObject):
7
    """Base class for experiment."""
8
9
    def __init__(self):
10
        super().__init__()
11
12
    def __call__(self, **kwargs):
13
        """Score parameters, with kwargs call."""
14
        score, _ = self.score(kwargs)
15
        return score
16
17
    @property
18
    def __name__(self):
19
        return type(self).__name__
20
21
    def paramnames(self):
22
        """Return the parameter names of the search.
23
24
        Returns
25
        -------
26
        list of str
27
            The parameter names of the search parameters.
28
        """
29
        return self._paramnames()
30
31
    def _paramnames(self):
32
        """Return the parameter names of the search.
33
34
        Returns
35
        -------
36
        list of str
37
            The parameter names of the search parameters.
38
        """
39
        raise NotImplementedError
40
41
    def score(self, params):
42
        """Score the parameters.
43
44
        Parameters
45
        ----------
46
        params : dict with string keys
47
            Parameters to score.
48
49
        Returns
50
        -------
51
        float
52
            The score of the parameters.
53
        dict
54
            Additional metadata about the search.
55
        """
56
        paramnames = self.paramnames()
57
        if not set(params.keys()) <= set(paramnames):
58
            raise ValueError("Parameters do not match.")
59
        return self._score(params)
60
61
    def _score(self, params):
62
        """Score the parameters.
63
64
        Parameters
65
        ----------
66
        params : dict with string keys
67
            Parameters to score.
68
69
        Returns
70
        -------
71
        float
72
            The score of the parameters.
73
        dict
74
            Additional metadata about the search.
75
        """
76
        raise NotImplementedError
77