-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpipeline_component.py
64 lines (48 loc) · 1.86 KB
/
pipeline_component.py
1
2
3
4
5
6
7
8
9
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
58
59
60
61
62
63
64
__all__ = ["PipelineComponent"]
class PipelineComponent:
r"""Class for implementing pipeline components.
Date:
2020
Author:
Luka Pečnik
License:
MIT
Attributes:
Name (str): Name of the pipeline component.
_params (Dict[str, ParameterDefinition]): Dictionary of components's parameters with possible values. Possible parameter values are given as an instance of the ParameterDefinition class.
See Also:
* :class:`niaaml.utilities.ParameterDefinition`
"""
Name = None
def __init__(self, **kwargs):
r"""Initialize pipeline component.
Notes:
_params variable should not be static as in some cases it is instance specific. See * :class:`niaaml.preprocessing.feature_selection.select_k_best.SelectKBest` for example.
"""
self._params = dict()
self.set_parameters(**kwargs)
def set_parameters(self, **kwargs):
r"""Set the parameters/arguments of the pipeline component."""
return
def get_params_dict(self):
r"""Return parameters definition dictionary."""
return self._params
def to_string(self):
r"""User friendly representation of the object.
Returns:
str: User friendly representation of the object.
"""
return "Name: {name}\nArguments:\n{args}"
def _parameters_to_string(self, dictionary):
r"""User friendly representation of component's parameters.
Arguments:
dictionary (dict): Dictionary of parameters.
Returns:
str: User friendly representation of component's parameters.
"""
args_string = ""
for key in dictionary:
args_string += "\t" + key + " = " + str(dictionary[key]) + "\n"
if len(args_string) == 0:
args_string = "None"
return args_string