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

Function process_qlib_data

examples/benchmarks/TFT/tft.py:94–120  ·  view source on GitHub ↗

Prepare data to fit the TFT model. Args: df: Original DataFrame. fillna: Whether to fill the data with the mean values. Returns: Transformed DataFrame.

(df, dataset, fillna=False)

Source from the content-addressed store, hash-verified

92
93
94def process_qlib_data(df, dataset, fillna=False):
95 """Prepare data to fit the TFT model.
96
97 Args:
98 df: Original DataFrame.
99 fillna: Whether to fill the data with the mean values.
100
101 Returns:
102 Transformed DataFrame.
103
104 """
105 # Several features selected manually
106 feature_col = DATASET_SETTING[dataset]["feature_col"]
107 label_col = [DATASET_SETTING[dataset]["label_col"]]
108 temp_df = df.loc[:, feature_col + label_col]
109 if fillna:
110 temp_df = fill_test_na(temp_df)
111 temp_df = temp_df.swaplevel()
112 temp_df = temp_df.sort_index()
113 temp_df = temp_df.reset_index(level=0)
114 dates = pd.to_datetime(temp_df.index)
115 temp_df["date"] = dates
116 temp_df["day_of_week"] = dates.dayofweek
117 temp_df["month"] = dates.month
118 temp_df["year"] = dates.year
119 temp_df["const"] = 1.0
120 return temp_df
121
122
123def process_predicted(df, col_name):

Callers 2

fitMethod · 0.85
predictMethod · 0.85

Calls 2

fill_test_naFunction · 0.85
sort_indexMethod · 0.45

Tested by

no test coverage detected