1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-04 11:30:57 +08:00

Merge branch 'main' of https://github.com/you-n-g/qlib into main

This commit is contained in:
Jactus
2020-11-12 17:06:05 +08:00
2 changed files with 7 additions and 26 deletions

View File

@@ -293,22 +293,6 @@ class GRU(Model):
preds = self.gru_model(x_test).detach().numpy()
return pd.Series(preds, index=index)
def save(self, filename, **kwargs):
with save_multiple_parts_file(filename) as model_dir:
model_path = os.path.join(model_dir, os.path.split(model_dir)[-1])
# Save model
torch.save(self.gru_model.state_dict(), model_path)
def load(self, buffer, **kwargs):
with unpack_archive_with_buffer(buffer) as model_dir:
# Get model name
_model_name = os.path.splitext(list(filter(lambda x: x.startswith("model.bin"), os.listdir(model_dir)))[0])[
0
]
_model_path = os.path.join(model_dir, _model_name)
# Load model
self.gru_model.load_state_dict(torch.load(_model_path))
self._fitted = True
class AverageMeter(object):

17
qlib/data/dataset/processor.py Normal file → Executable file
View File

@@ -112,16 +112,13 @@ class Fillna(Processor):
"""Process infinity """
def __call__(self, df):
def fill_na(data):
def process_na(df):
for col in df.columns:
# FIXME: Such behavior is very weird
df[col] = df[col].fillna(0)
return df
def fill_na(df):
for col in df.columns:
# FIXME: Such behavior is very weird
df[col] = df[col].fillna(0)
data = datetime_groupby_apply(data, process_na)
data.sort_index(inplace=True)
return data
df.sort_index(inplace=True)
return df
return fill_na(df)
@@ -163,7 +160,7 @@ class ZscoreNorm(Processor):
df = fetch_df_by_index(df, slice(self.fit_start_time, self.fit_end_time), level="datetime")
cols = get_group_columns(df, self.fields_group)
self.mean_train = np.nanmean(df[cols].values, axis=0)
self.std_train = np.nanstd(_df[cols].values, axis=0)
self.std_train = np.nanstd(df[cols].values, axis=0)
self.ignore = self.std_train == 0
self.cols = cols