mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-11 14:56:55 +08:00
pylint code refine & Fix nested example (#848)
* refine code by CI * fix argument error * fix nested eample
This commit is contained in:
@@ -63,9 +63,7 @@ def _get_date_parse_fn(target):
|
||||
get_date_parse_fn('20120101')('2017-01-01') => '20170101'
|
||||
get_date_parse_fn(20120101)('2017-01-01') => 20170101
|
||||
"""
|
||||
if isinstance(target, pd.Timestamp):
|
||||
_fn = lambda x: pd.Timestamp(x) # Timestamp('2020-01-01')
|
||||
elif isinstance(target, int):
|
||||
if isinstance(target, int):
|
||||
_fn = lambda x: int(str(x).replace("-", "")[:8]) # 20200201
|
||||
elif isinstance(target, str) and len(target) == 8:
|
||||
_fn = lambda x: str(x).replace("-", "")[:8] # '20200201'
|
||||
@@ -158,7 +156,7 @@ class MTSDatasetH(DatasetH):
|
||||
try:
|
||||
df = self.handler._learn.copy() # use copy otherwise recorder will fail
|
||||
# FIXME: currently we cannot support switching from `_learn` to `_infer` for inference
|
||||
except:
|
||||
except Exception:
|
||||
warnings.warn("cannot access `_learn`, will load raw data")
|
||||
df = self.handler._data.copy()
|
||||
df.index = df.index.swaplevel()
|
||||
|
||||
@@ -371,7 +371,7 @@ def long_short_backtest(
|
||||
|
||||
def t_run():
|
||||
pred_FN = "./check_pred.csv"
|
||||
pred = pd.read_csv(pred_FN)
|
||||
pred: pd.DataFrame = pd.read_csv(pred_FN)
|
||||
pred["datetime"] = pd.to_datetime(pred["datetime"])
|
||||
pred = pred.set_index([pred.columns[0], pred.columns[1]])
|
||||
pred = pred.iloc[:9000]
|
||||
|
||||
@@ -554,7 +554,7 @@ class AdaRNN(nn.Module):
|
||||
return fc_out
|
||||
|
||||
|
||||
class TransferLoss(object):
|
||||
class TransferLoss:
|
||||
def __init__(self, loss_type="cosine", input_dim=512):
|
||||
"""
|
||||
Supported loss_type: mmd(mmd_lin), mmd_rbf, coral, cosine, kl, js, mine, adv
|
||||
|
||||
@@ -98,7 +98,6 @@ class DNNModelPytorch(Model):
|
||||
"\nlr_decay_steps : {}"
|
||||
"\noptimizer : {}"
|
||||
"\nloss_type : {}"
|
||||
"\neval_steps : {}"
|
||||
"\nseed : {}"
|
||||
"\ndevice : {}"
|
||||
"\nuse_GPU : {}"
|
||||
@@ -113,7 +112,6 @@ class DNNModelPytorch(Model):
|
||||
lr_decay_steps,
|
||||
optimizer,
|
||||
loss,
|
||||
eval_steps,
|
||||
seed,
|
||||
self.device,
|
||||
self.use_gpu,
|
||||
@@ -331,8 +329,8 @@ class Net(nn.Module):
|
||||
dnn_layers = []
|
||||
drop_input = nn.Dropout(0.05)
|
||||
dnn_layers.append(drop_input)
|
||||
for i, (input_dim, hidden_units) in enumerate(zip(layers[:-1], layers[1:])):
|
||||
fc = nn.Linear(input_dim, hidden_units)
|
||||
for i, (_input_dim, hidden_units) in enumerate(zip(layers[:-1], layers[1:])):
|
||||
fc = nn.Linear(_input_dim, hidden_units)
|
||||
activation = nn.LeakyReLU(negative_slope=0.1, inplace=False)
|
||||
bn = nn.BatchNorm1d(hidden_units)
|
||||
seq = nn.Sequential(fc, bn, activation)
|
||||
|
||||
@@ -19,7 +19,7 @@ import torch.nn.functional as F
|
||||
|
||||
try:
|
||||
from torch.utils.tensorboard import SummaryWriter
|
||||
except:
|
||||
except ImportError:
|
||||
SummaryWriter = None
|
||||
|
||||
from tqdm import tqdm
|
||||
@@ -257,7 +257,7 @@ class TRAModel(Model):
|
||||
total_loss += loss.item()
|
||||
total_count += 1
|
||||
|
||||
if self.use_daily_transport and len(P_all):
|
||||
if self.use_daily_transport and len(P_all) > 0:
|
||||
P_all = pd.concat(P_all, axis=0)
|
||||
prob_all = pd.concat(prob_all, axis=0)
|
||||
choice_all = pd.concat(choice_all, axis=0)
|
||||
|
||||
@@ -15,7 +15,6 @@ from plotly.figure_factory import create_distplot
|
||||
|
||||
|
||||
class BaseGraph:
|
||||
""" """
|
||||
|
||||
_name = None
|
||||
|
||||
@@ -297,8 +296,8 @@ class SubplotsGraph:
|
||||
|
||||
:return:
|
||||
"""
|
||||
self._sub_graph_data = list()
|
||||
self._subplot_titles = list()
|
||||
self._sub_graph_data = []
|
||||
self._subplot_titles = []
|
||||
|
||||
for i, column_name in enumerate(self._df.columns):
|
||||
row = math.ceil((i + 1) / self.__cols)
|
||||
|
||||
Reference in New Issue
Block a user