qlib icon indicating copy to clipboard operation
qlib copied to clipboard

score_ic_graph got nan data and throw error

Open lerit opened this issue 2 years ago • 1 comments

follow office document,analysis score IC:

pred_df = recorder.load_object("pred.pkl")

pred_df_dates = pred_df.index.get_level_values(level='datetime')
features_df = D.features(D.instruments('csi500'), ['Ref($close, -2)/Ref($close, -1)-1'], pred_df_dates.min(), pred_df_dates.max())
features_df.columns = ['label']
pred_label = pd.concat([features_df, pred], axis=1, sort=True).reindex(features_df.index)
analysis_position.score_ic_graph(pred_label)

but score_ic_graph throw error:

If using all scalar values, you must pass an index

with debug,score_ic.py drop nan:

concat_data.dropna(axis=0, how="any", inplace=True)

print dataframe for debug,the third variable(pred_label) with nan:

image

is features_df or pred with wrong format cause nan?

lerit avatar Aug 20 '22 04:08 lerit

i guess because features_df and pred with different MultiIndex,so use below code to transform it:

pred_df = pred_df.swaplevel(0, 1)
pred_df.sort_index(inplace=True)

now,it work without error,is it a right transform?and why office demo without transform?

lerit avatar Aug 25 '22 03:08 lerit

This issue is stale because it has been open for three months with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

github-actions[bot] avatar Nov 23 '22 06:11 github-actions[bot]