diff --git a/gamestonk_terminal/config_neural_network_models.py b/gamestonk_terminal/config_neural_network_models.py index 5408539bb13..38ef798e18e 100644 --- a/gamestonk_terminal/config_neural_network_models.py +++ b/gamestonk_terminal/config_neural_network_models.py @@ -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" diff --git a/gamestonk_terminal/prediction_techniques/neural_networks_view.py b/gamestonk_terminal/prediction_techniques/neural_networks_view.py index 30357106fb8..e88b59a679d 100644 --- a/gamestonk_terminal/prediction_techniques/neural_networks_view.py +++ b/gamestonk_terminal/prediction_techniques/neural_networks_view.py @@ -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( diff --git a/gamestonk_terminal/prediction_techniques/pred_helper.py b/gamestonk_terminal/prediction_techniques/pred_helper.py index 9ce767451e6..197a5c16e2a 100644 --- a/gamestonk_terminal/prediction_techniques/pred_helper.py +++ b/gamestonk_terminal/prediction_techniques/pred_helper.py @@ -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