mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-13 07:46:53 +08:00
Add TabNet config
This commit is contained in:
@@ -9,19 +9,24 @@ from ...model.base import Model
|
||||
from ...data.dataset import DatasetH
|
||||
from ...data.dataset.handler import DataHandlerLP
|
||||
|
||||
|
||||
class TabNetModel(Model):
|
||||
"""TabNetModel Model"""
|
||||
|
||||
def __init__(self, n_d, n_a,
|
||||
n_steps,
|
||||
gamma,
|
||||
n_independent,
|
||||
n_shared,
|
||||
seed,
|
||||
momentum,
|
||||
lambda_sparse,
|
||||
optimizer_params,
|
||||
**kwargs):
|
||||
def __init__(
|
||||
self,
|
||||
n_d,
|
||||
n_a,
|
||||
n_steps,
|
||||
gamma,
|
||||
n_independent,
|
||||
n_shared,
|
||||
seed,
|
||||
momentum,
|
||||
lambda_sparse,
|
||||
optimizer_params,
|
||||
**kwargs
|
||||
):
|
||||
self.model = None
|
||||
|
||||
self.n_d = n_d
|
||||
@@ -47,28 +52,28 @@ class TabNetModel(Model):
|
||||
seed=0,
|
||||
momentum=0.02,
|
||||
lambda_sparse=1e-3,
|
||||
optimizer_params={'lr':2e-3},
|
||||
optimizer_params={"lr": 2e-3},
|
||||
**kwargs
|
||||
):
|
||||
|
||||
df_train, df_valid = dataset.prepare(
|
||||
["train", "valid"], col_set=["feature", "label"], data_key=DataHandlerLP.DK_L
|
||||
)
|
||||
x_train, y_train = df_train["feature"].values, df_train["label"].values*100
|
||||
x_valid, y_valid = df_valid["feature"].values, df_valid["label"].values*100
|
||||
x_train, y_train = df_train["feature"].values, df_train["label"].values * 100
|
||||
x_valid, y_valid = df_valid["feature"].values, df_valid["label"].values * 100
|
||||
|
||||
self.model = TabNetRegressor(
|
||||
n_d=self.n_d,
|
||||
n_a=self.n_a,
|
||||
n_steps=self.n_steps,
|
||||
gamma=self.gamma,
|
||||
n_independent=self.n_independent,
|
||||
n_shared=self.n_shared,
|
||||
seed=self.seed,
|
||||
momentum=self.momentum,
|
||||
lambda_sparse=self.lambda_sparse,
|
||||
optimizer_params=self.optimizer_params,
|
||||
**kwargs
|
||||
n_d=self.n_d,
|
||||
n_a=self.n_a,
|
||||
n_steps=self.n_steps,
|
||||
gamma=self.gamma,
|
||||
n_independent=self.n_independent,
|
||||
n_shared=self.n_shared,
|
||||
seed=self.seed,
|
||||
momentum=self.momentum,
|
||||
lambda_sparse=self.lambda_sparse,
|
||||
optimizer_params=self.optimizer_params,
|
||||
**kwargs
|
||||
)
|
||||
self.model.fit(x_train, y_train, eval_set=[(x_valid, y_valid)])
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ class BaseStrategy:
|
||||
return 0.95
|
||||
|
||||
def generate_order_list(self, score_series, current, trade_exchange, pred_date, trade_date):
|
||||
"""Parameter
|
||||
"""
|
||||
Parameters:
|
||||
-----------
|
||||
score_series : pd.Seires
|
||||
stock_id , score
|
||||
current : Position()
|
||||
@@ -44,8 +46,8 @@ class BaseStrategy:
|
||||
|
||||
def update(self, score_series, pred_date, trade_date):
|
||||
"""User can use this method to update strategy state each trade date.
|
||||
Parameter
|
||||
---------
|
||||
Parameters:
|
||||
-----------
|
||||
score_series : pd.Series
|
||||
stock_id , score
|
||||
pred_date : pd.Timestamp
|
||||
@@ -97,7 +99,7 @@ class AdjustTimer:
|
||||
Responsible for timing of position adjusting
|
||||
|
||||
This is designed as multiple inheritance mechanism due to
|
||||
- the is_adjust may need access to the internel state of a strategyw
|
||||
- the is_adjust may need access to the internel state of a strategy
|
||||
- it can be reguard as a enhancement to the existing strategy
|
||||
"""
|
||||
|
||||
@@ -139,7 +141,7 @@ class WeightStrategyBase(BaseStrategy, AdjustTimer):
|
||||
def generate_target_weight_position(self, score, current, trade_date):
|
||||
"""
|
||||
Parameters:
|
||||
---------
|
||||
-----------
|
||||
score : pred score for this trade date, pd.Series, index is stock_id, contain 'score' column
|
||||
current : current position, use Position() class
|
||||
trade_exchange : Exchange()
|
||||
@@ -228,7 +230,7 @@ class TopkDropoutStrategy(BaseStrategy, ListAdjustTimer):
|
||||
Gnererate order list according to score_series at trade_date, will not change current.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
-----------
|
||||
score_series : pd.Series
|
||||
stock_id , score
|
||||
current : Position()
|
||||
|
||||
Reference in New Issue
Block a user