macrosynergy.learning.forecasting.nn#
- class MLPRegressor(n_latent, loss_func=MSELoss(), weight_decay=0.0001, reg_turnover=0, batch_size=16, learning_rate=0.0003, use_ts_sampler=True, encoder_activation='tanh', head_activation='identity', fit_encoder_intercept=False, fit_head_intercept=True, epochs=10000, patience=1000, train_pct=0.7, verbose=False, random_state=42, inverse_transform_preds=False)[source]#
Bases:
BaseEstimator,RegressorMixinScikit-learn compatible multi-layer perceptron (MLP) regressor implemented in PyTorch.
This estimator wraps
macrosynergy.learning.forecasting.torch.MultiLayerPerceptronand trains it viamacrosynergy.learning.forecasting.torch.MLPTrainer, including optional scaling of inputs and targets usingsklearn.preprocessing.StandardScaler.- Parameters:
n_latent (int) – Number of hidden units in the latent layer of the MLP.
loss_func (torch.nn.Module, optional) – Loss function used during training. Default is
nn.MSELoss().weight_decay (float, optional) – L2 regularization strength applied via the optimizer. Default is 1e-4.
reg_turnover (float, optional) – Additional turnover regularization penalty applied by the trainer. Default is 0.
batch_size (int, optional) – Batch size used during training. Default is 16.
learning_rate (float, optional) – Learning rate used by the optimizer. Default is 3e-4.
use_ts_sampler (bool, optional) – Whether to use time-series batch sampling during training. Default is True.
encoder_activation (str, optional) – Activation function for the encoder (hidden) component of the network. Default is “tanh”.
head_activation (str, optional) – Activation function for the head (output) component of the network. Default is “identity”.
fit_encoder_intercept (bool, optional) – Whether to include an intercept (bias term) in the encoder layers. Default is False.
fit_head_intercept (bool, optional) – Whether to include an intercept (bias term) in the output layer. Default is True.
epochs (int, optional) – Maximum number of training epochs. Default is 10000.
patience (int, optional) – Number of epochs to wait for improvement before early stopping. Default is 1000.
train_pct (float, optional) – Fraction of samples used for training (remainder used for validation). Default is 0.7.
verbose (bool, optional) – Whether to print training diagnostics. Default is False.
random_state (int, optional) – Random seed used for PyTorch initialization and training. Default is 42.
inverse_transform_preds (bool, optional) – Whether to inverse-transform predictions back to the original target scale using the fitted target scaler. Default is False.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MLPRegressor#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.