-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlmodel.py
35 lines (24 loc) · 946 Bytes
/
mlmodel.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
from scores import scores
from sklearn.base import clone
class mlmodel:
def __init__(self, model, name, *args, **kwargs):
self.model = model
self.name = name
self.scores = scores()
self.args = args
self.kwargs = kwargs
# all methods and attributes are passed to the estimator object
def __getattr__(self, attr: str):
# just to be pickable
if attr.startswith('__') and attr.endswith('__'):
raise AttributeError
return getattr(self.model, attr)
def __repr__(self) -> str:
return f'{self.name}\nscores:{str(self.scores.scores)}'
def __str__(self) -> str:
return f'{self.name}\nscores:{str(self.scores.scores)}'
def mlclone(mlmodel_: mlmodel) -> mlmodel:
assert isinstance(mlmodel_, mlmodel)
return mlmodel(clone(mlmodel_.model), str(mlmodel_.name))
if __name__ == '__main__':
print('ML model class file.')