mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Put loss and preprocesser in cfg file
This commit is contained in:
@@ -56,3 +56,15 @@ Optimizer = "Adam"
|
||||
# Add early stopping to save time training when validation is plateaued
|
||||
# Can be set to large number or None to ignore
|
||||
Early_Stop_Patience = 10
|
||||
|
||||
# Losses https://www.tensorflow.org/api_docs/python/tf/keras/losses
|
||||
# mae, mape, mse, msle, poisson, logcosh, kld, hinge, squared_hinge, huber
|
||||
Loss = "mae"
|
||||
|
||||
# Preprocessing technique to use : https://scikit-learn.org/stable/modules/preprocessing.html
|
||||
# Options are:
|
||||
# minmax - Adjusts data to be between 0 and 1 - Most Used for Stocks
|
||||
# standardization - Standardizes data so that it has mean 0 and standard deviation = 1
|
||||
# normalization - Normalizes data so that L2 norm (sum x_i^2) = 1
|
||||
# none - No preprocessing
|
||||
Preprocess = "minmax"
|
||||
|
||||
@@ -193,7 +193,7 @@ def mlp(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
)
|
||||
model.compile(
|
||||
optimizer=optimizers[cfg_nn_models.Optimizer](lr=ns_parser.lr),
|
||||
loss=ns_parser.s_loss,
|
||||
loss=cfg_nn_models.Loss,
|
||||
)
|
||||
|
||||
model.fit(
|
||||
@@ -303,7 +303,7 @@ def rnn(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
)
|
||||
model.compile(
|
||||
optimizer=optimizers[cfg_nn_models.Optimizer](lr=ns_parser.lr),
|
||||
loss=ns_parser.s_loss,
|
||||
loss=cfg_nn_models.Loss,
|
||||
)
|
||||
model.fit(
|
||||
X_train.reshape(X_train.shape[0], X_train.shape[1], 1),
|
||||
@@ -410,7 +410,7 @@ def lstm(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
)
|
||||
model.compile(
|
||||
optimizer=optimizers[cfg_nn_models.Optimizer](lr=ns_parser.lr),
|
||||
loss=ns_parser.s_loss,
|
||||
loss=cfg_nn_models.Loss,
|
||||
)
|
||||
|
||||
model.fit(
|
||||
@@ -521,7 +521,7 @@ def conv1d(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
|
||||
model.compile(
|
||||
optimizer=optimizers[cfg_nn_models.Optimizer](lr=ns_parser.lr),
|
||||
loss=ns_parser.s_loss,
|
||||
loss=cfg_nn_models.Loss,
|
||||
)
|
||||
|
||||
model.fit(
|
||||
|
||||
@@ -25,6 +25,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
valid_date,
|
||||
plot_autoscale,
|
||||
)
|
||||
from gamestonk_terminal import config_neural_network_models as cfg
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
|
||||
@@ -39,6 +40,8 @@ simplefilter(action="ignore", category=FutureWarning)
|
||||
ORIGINAL_TF_XLA_FLAGS = os.environ.get("TF_XLA_FLAGS")
|
||||
ORIGINAL_TF_FORCE_GPU_ALLOW_GROWTH = os.environ.get("TF_FORCE_GPU_ALLOW_GROWTH")
|
||||
|
||||
PREPROCESSER = cfg.Preprocess
|
||||
|
||||
|
||||
def check_valid_frac(num) -> float:
|
||||
if (num < 0) or (num > 1):
|
||||
@@ -109,44 +112,6 @@ def parse_args(prog: str, description: str, other_args: List[str]):
|
||||
default=50,
|
||||
help="number of training epochs.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-j",
|
||||
"--jumps",
|
||||
action="store",
|
||||
dest="n_jumps",
|
||||
type=check_positive,
|
||||
default=1,
|
||||
help="number of jumps in training data.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--pp",
|
||||
action="store",
|
||||
dest="s_preprocessing",
|
||||
default="minmax",
|
||||
choices=["normalization", "standardization", "minmax", "none"],
|
||||
help="pre-processing data.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--loss",
|
||||
action="store",
|
||||
dest="s_loss",
|
||||
default="mae",
|
||||
choices=[
|
||||
"mae",
|
||||
"mape",
|
||||
"mse",
|
||||
"msle",
|
||||
"poisson",
|
||||
"logcosh",
|
||||
"kld",
|
||||
"hinge",
|
||||
"squared_hinge",
|
||||
"huber",
|
||||
],
|
||||
help="loss function (see https://www.tensorflow.org/api_docs/python/tf/keras/losses)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-e",
|
||||
"--end",
|
||||
@@ -293,16 +258,16 @@ def prepare_scale_train_valid_test(
|
||||
test_size = ns_parser.valid_split
|
||||
|
||||
# Pre-process data
|
||||
if ns_parser.s_preprocessing == "standardization":
|
||||
if PREPROCESSER == "standardization":
|
||||
scaler = StandardScaler()
|
||||
|
||||
elif ns_parser.s_preprocessing == "minmax":
|
||||
elif PREPROCESSER == "minmax":
|
||||
scaler = MinMaxScaler()
|
||||
|
||||
elif ns_parser.s_preprocessing == "normalization":
|
||||
elif PREPROCESSER == "normalization":
|
||||
scaler = Normalizer()
|
||||
|
||||
elif ns_parser.s_preprocessing == "none":
|
||||
elif (PREPROCESSER == "none") or (PREPROCESSER is None):
|
||||
scaler = None
|
||||
# Test data is used for forecasting. Takes the last n_input_days data points.
|
||||
# These points are not fed into training
|
||||
|
||||
Reference in New Issue
Block a user