MCPcopy
hub / github.com/microsoft/qlib / train

Function train

tests/test_all_pipeline.py:19–60  ·  view source on GitHub ↗

train model Returns ------- pred_score: pandas.DataFrame predict scores performance: dict model performance

(uri_path: str = None)

Source from the content-addressed store, hash-verified

17
18
19def train(uri_path: str = None):
20 """train model
21
22 Returns
23 -------
24 pred_score: pandas.DataFrame
25 predict scores
26 performance: dict
27 model performance
28 """
29
30 # model initialization
31 model = init_instance_by_config(CSI300_GBDT_TASK["model"])
32 dataset = init_instance_by_config(CSI300_GBDT_TASK["dataset"])
33 # To test __repr__
34 print(dataset)
35 print(R)
36
37 # start exp
38 with R.start(experiment_name="workflow", uri=uri_path):
39 R.log_params(**flatten_dict(CSI300_GBDT_TASK))
40 model.fit(dataset)
41 R.save_objects(trained_model=model)
42 # prediction
43 recorder = R.get_recorder()
44 # To test __repr__
45 print(recorder)
46 # To test get_local_dir
47 print(recorder.get_local_dir())
48 rid = recorder.id
49 sr = SignalRecord(model, dataset, recorder)
50 sr.generate()
51 pred_score = sr.load("pred.pkl")
52
53 # calculate ic and ric
54 sar = SigAnaRecord(recorder)
55 sar.generate()
56 ic = sar.load("ic.pkl")
57 ric = sar.load("ric.pkl")
58
59 uri_path = R.get_uri()
60 return pred_score, {"ic": ic, "ric": ric}, rid, uri_path
61
62
63def fake_experiment():

Callers 1

test_0_trainMethod · 0.70

Calls 14

generateMethod · 0.95
init_instance_by_configFunction · 0.90
flatten_dictFunction · 0.90
SignalRecordClass · 0.90
SigAnaRecordClass · 0.90
get_local_dirMethod · 0.80
get_uriMethod · 0.80
startMethod · 0.45
log_paramsMethod · 0.45
fitMethod · 0.45
save_objectsMethod · 0.45
get_recorderMethod · 0.45

Tested by

no test coverage detected