python - Create dictionary for classification dataset storage similar to digits dataset (sklearn) -
i extracting features images , save them alongside labels (and original images preferably) able load them later without running code feature extraction every time.
i store them in in similar structure 1 digits dataset in sklearn.datasets, dictionary type.
so problem not storing of type key:value, of type:
- features (x)
- target_labels (y)
- images (optional)
- target_names
my x numpy.ndarray data type , y 1-d vector array.
any suggestions how achieve this?
if want sklearn.datasets methods return why don't use code?
they define class bunch want:
class bunch(dict): """container object datasets dictionary-like object exposes keys attributes. >>> b = bunch(a=1, b=2) >>> b['b'] 2 >>> b.b 2 >>> b.a = 3 >>> b['a'] 3 >>> b.c = 6 >>> b['c'] 6 """ def __init__(self, **kwargs): super(bunch, self).__init__(kwargs) def __setattr__(self, key, value): self[key] = value def __dir__(self): return self.keys() def __getattr__(self, key): try: return self[key] except keyerror: raise attributeerror(key) and create dataset object with:
bunch(data=data, target=target, target_names=target_names, descr=fdescr, feature_names=['feat_1', 'feat_2', 'feat_3', 'feat_4'])
Comments
Post a Comment