Total Complexity | 8 |
Total Lines | 77 |
Duplicated Lines | 0 % |
Changes | 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 |