1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-09 22:10:56 +08:00

Add MultiSegRecord in contrib.workflow and decouple its tests from test_all_pipeline

This commit is contained in:
D-X-Y
2021-03-28 00:33:59 -07:00
parent 0387eaf7ab
commit 9d04ae4676
7 changed files with 171 additions and 27 deletions

View File

@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from .record_temp import MultiSegRecord
from .record_temp import SignalMseRecord

View File

@@ -5,14 +5,43 @@ import re
import pandas as pd
from sklearn.metrics import mean_squared_error
from pprint import pprint
from typing import Dict, Text, Any
import numpy as np
from ...workflow.record_temp import RecordTemp
from ...workflow.record_temp import SignalRecord
from ...data import dataset as qlib_dataset
from ...log import get_module_logger
logger = get_module_logger("workflow", "INFO")
class MultiSegRecord(RecordTemp):
"""
This is the multiple segments signal record class that generates the signal prediction.
This class inherits the ``RecordTemp`` class.
"""
def __init__(self, model, dataset, recorder=None):
super().__init__(recorder=recorder)
if not isinstance(dataset, qlib_dataset.DatasetH):
raise ValueError("The type of dataset is not DatasetH instead of {:}".format(type(dataset)))
self.model = model
self.dataset = dataset
def generate(self, segments: Dict[Text, Any], save: bool = False):
# generate prediciton
for key, segment in segments.items():
predics = self.model.predict(self.dataset, segment)
if isinstance(pred, pd.Series):
predics = predictions.to_frame("score")
# self.recorder.save_objects(**{"pred.pkl": pred})
labels = self.dataset.prepare(
segments=segment, col_set="label", data_key=dataset.handler.DataHandlerLP.DK_R
)
# compute ic, rank_ic
class SignalMseRecord(SignalRecord):
"""
This is the Signal MSE Record class that computes the mean squared error (MSE).