-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathabstract_data_manager.py
72 lines (56 loc) · 1.93 KB
/
abstract_data_manager.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
65
66
67
68
69
70
71
72
import abc
from typing import Any, Dict, Union
import numpy as np
import scipy.sparse
from autosklearn.pipeline.components.data_preprocessing.feature_type import (
FeatTypeSplit,
)
class AbstractDataManager:
__metaclass__ = abc.ABCMeta
def __init__(self, name: str):
self._data = dict() # type: Dict
self._info = dict() # type: Dict
self._name = name
@property
def name(self) -> str:
return self._name
@property
def data(self) -> Dict[str, np.ndarray]:
return self._data
@property
def info(self) -> Dict[str, Any]:
return self._info
@property
def feat_type(self) -> Dict[Union[str, int], str]:
return self._feat_type
@feat_type.setter
def feat_type(self, value: Dict[Union[str, int], str]) -> None:
self._feat_type = value
@property
def encoder(self) -> FeatTypeSplit:
return self._encoder
@encoder.setter
def encoder(self, value: FeatTypeSplit) -> FeatTypeSplit:
self._encoder = value
def __repr__(self) -> str:
return "DataManager : " + self.name
def __str__(self) -> str:
val = "DataManager : " + self.name + "\ninfo:\n"
for item in self.info:
val = val + "\t" + item + " = " + str(self.info[item]) + "\n"
val = val + "data:\n"
for subset in self.data:
val = val + "\t%s = %s %s %s\n" % (
subset,
type(self.data[subset]),
str(self.data[subset].shape),
str(self.data[subset].dtype),
)
if isinstance(self.data[subset], scipy.sparse.spmatrix):
val = val + "\tdensity: %f\n" % (
float(len(self.data[subset].data))
/ self.data[subset].shape[0]
/ self.data[subset].shape[1]
)
val = val + "feat_type:\t" + str(self.feat_type) + "\n"
return val