Passed
Pull Request — master (#101)
by Simon
01:32
created

BaseExperiment.score()   A

Complexity

Conditions 2

Size

Total Lines 19
Code Lines 5

Duplication

Lines 19
Ratio 100 %

Importance

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