Total Complexity | 7 |
Total Lines | 72 |
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 | return self.score(kwargs) |
||
15 | |||
16 | def paramnames(self): |
||
17 | """Return the parameter names of the search. |
||
18 | |||
19 | Returns |
||
20 | ------- |
||
21 | list of str |
||
22 | The parameter names of the search parameters. |
||
23 | """ |
||
24 | return self._paramnames() |
||
25 | |||
26 | def _paramnames(self): |
||
27 | """Return the parameter names of the search. |
||
28 | |||
29 | Returns |
||
30 | ------- |
||
31 | list of str |
||
32 | The parameter names of the search parameters. |
||
33 | """ |
||
34 | raise NotImplementedError |
||
35 | |||
36 | def score(self, **params): |
||
37 | """Score the parameters. |
||
38 | |||
39 | Parameters |
||
40 | ---------- |
||
41 | params : dict with string keys |
||
42 | Parameters to score. |
||
43 | |||
44 | Returns |
||
45 | ------- |
||
46 | float |
||
47 | The score of the parameters. |
||
48 | dict |
||
49 | Additional metadata about the search. |
||
50 | """ |
||
51 | paramnames = self.paramnames() |
||
52 | if not set(paramnames) == set(params.keys()): |
||
53 | raise ValueError("Parameters do not match.") |
||
54 | return self._score(**params) |
||
55 | |||
56 | def _score(self, **params): |
||
57 | """Score the parameters. |
||
58 | |||
59 | Parameters |
||
60 | ---------- |
||
61 | params : dict with string keys |
||
62 | Parameters to score. |
||
63 | |||
64 | Returns |
||
65 | ------- |
||
66 | float |
||
67 | The score of the parameters. |
||
68 | dict |
||
69 | Additional metadata about the search. |
||
70 | """ |
||
71 | raise NotImplementedError |
||
72 |