mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-14 16:26:55 +08:00
add downcast to save data
This commit is contained in:
@@ -130,25 +130,25 @@ class SignalRecord(RecordTemp):
|
|||||||
pprint(f"The following are prediction results of the {type(self.model).__name__} model.")
|
pprint(f"The following are prediction results of the {type(self.model).__name__} model.")
|
||||||
pprint(pred.head(5))
|
pprint(pred.head(5))
|
||||||
|
|
||||||
# save according label
|
if isinstance(self.dataset, DatasetH):
|
||||||
if isinstance(self.dataset, TSDatasetH):
|
# NOTE:
|
||||||
index = raw_label.get_index()
|
# Python doesn't provide the downcasting mechanism.
|
||||||
raw_label = raw_label.data.loc[index]
|
# We use the trick here to downcast the class
|
||||||
raw_label = raw_label[:, -1:]
|
orig_cls = self.dataset.__class__
|
||||||
self.recorder.save_objects(**{"label.pkl": raw_label})
|
self.dataset.__class__ = DatasetH
|
||||||
|
|
||||||
elif isinstance(self.dataset, DatasetH):
|
params = dict(segments="test", col_set="label", data_key=DataHandlerLP.DK_R)
|
||||||
params = dict(self=self.dataset, segments="test", col_set="label", data_key=DataHandlerLP.DK_R)
|
|
||||||
try:
|
try:
|
||||||
# Assume the backend handler is DataHandlerLP
|
# Assume the backend handler is DataHandlerLP
|
||||||
raw_label = DatasetH.prepare(**params)
|
raw_label = self.dataset.prepare(**params)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# The argument number is not right
|
# The argument number is not right
|
||||||
del params["data_key"]
|
del params["data_key"]
|
||||||
# The backend handler should be DataHandler
|
# The backend handler should be DataHandler
|
||||||
raw_label = DatasetH.prepare(**params)
|
raw_label = self.dataset.prepare(**params)
|
||||||
|
|
||||||
self.recorder.save_objects(**{"label.pkl": raw_label})
|
self.recorder.save_objects(**{"label.pkl": raw_label})
|
||||||
|
self.dataset.__class__ = orig_cls
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
return ["pred.pkl", "label.pkl"]
|
return ["pred.pkl", "label.pkl"]
|
||||||
|
|||||||
Reference in New Issue
Block a user