time_series_predictor package
Subpackages
Submodules
time_series_predictor.l1_regularized_nnr module
L1 regularized NNR
- class time_series_predictor.l1_regularized_nnr.L1RegularizedNNR(*args, lambda1=0, **kwargs)
Bases:
skorch.regressor.NeuralNetRegressor
L1 regularization
\[L_{loss}=\left \| y-\hat{y} \right \|^2+\lambda | W |\]L1 regularization makes the weight vector sparse during the optimization process.
The optimizer in PyTorch can only implement L2 regularization, and L1 regularization needs to be implemented manually, that is the purpose of this class.
Note
This example also regularizes the biases, which you typically don’t need to do.
- get_loss(y_pred, y_true, X=None, training=False)
Return the loss for this batch.
- Parameters
y_pred (torch tensor) – Predicted target values
y_true (torch tensor) – True target values.
X (input data, compatible with skorch.dataset.Dataset) –
By default, you should be able to pass:
numpy arrays
torch tensors
pandas DataFrame or Series
scipy sparse CSR matrices
a dictionary of the former three
a list/tuple of the former three
a Dataset
If this doesn’t work with your data, you have to pass a
Dataset
that can deal with the data.training (bool (default=False)) – Whether train mode should be used or not.
- set_input_shape(X, y)
time_series_predictor.min_max_scaler module
min_max_scaler
- class time_series_predictor.min_max_scaler.MinMaxScaler
Bases:
time_series_predictor.sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Min Max Scaler class
- fit(X, *_args, **_kwargs)
Compute the minimum and maximum to be used for later scaling.
- Parameters
input_matrix – input matrix
axis – None or int or tuple of ints, optional Axis or axes along which to operate.
- fit_transform(X, y=None, **fit_params)
Fit to data, then transform it.
- Parameters
input_matrix – input matrix
- Returns
transformed matrix
- inverse_transform(transformed)
- Parameters
transformed – transformed input
- Returns
inverse transformed
- transform(X)
Scale features of input_matrix according to feature_range.
- Parameters
input_matrix – input matrix
- Returns
transformed matrix
time_series_predictor.time_series_predictor module
time_series_predictor script
- class time_series_predictor.time_series_predictor.CheckpointHandler
Bases:
skorch.callbacks.base.Callback
- on_train_end(net, X=None, y=None, **kwargs)
Called at the end of training.
- class time_series_predictor.time_series_predictor.InputShapeSetter
Bases:
skorch.callbacks.base.Callback
dynamically set the input size of the PyTorch module based on the data
Typically, it’s up to the user to determine the shape of the input data when defining the PyTorch module. This can sometimes be inconvenient, e.g. when the shape is only known at runtime. E.g., when using
sklearn.feature_selection.VarianceThreshold
, you cannot know the number of features in advance. The best solution would be to set the input size dynamically.- on_train_begin(net, X=None, y=None, **kwargs)
Called at the beginning of training.
- class time_series_predictor.time_series_predictor.ScoreCalculator(scores_to_calculate, locks, score_method, output_list)
Bases:
threading.Thread
Spread computational effort across cpus
- run()
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- class time_series_predictor.time_series_predictor.TimeSeriesPredictor(net, early_stopping=None, **l1_regularized_nnr_params)
Bases:
object
Network agnostic time series predictor class
- Parameters
**l1_regularized_nnr_params (skorch L1RegularizedNNR parameters.) –
early_stopping (torch.callbacks.EarlyStopping object) –
- fit(dataset, **fit_params)
Fit selected network
- Parameters
dataset (dataset to fit on) –
net (network to use) –
**fit_params (dict) – Additional parameters passed to the forward method of the module and to the self.train_split call.
- forecast(*args, **kwargs)
Future forecast
- Parameters
*args (variable length unnamed args list) –
**kwargs (variable length named args list) –
- Returns
future forecast
- Returns
future dataframe
- make_future_dataframe(*args, **kwargs)
- Parameters
*args (variable length unnamed args list) –
**kwargs (variable length named args list) –
- Returns
future dataframe
- predict(inp)
Run predictions
- Parameters
inp – input
- sample_forecast(*args, **kwargs)
Future forecast
- Parameters
*args (variable length unnamed args list) –
**kwargs (variable length named args list) –
- Returns
future forecast
- Returns
future dataframe
- sample_predict(inp)
Run predictions
- Parameters
inp – input
- score(dataset)
Compute the mean r2_score of a network on a given dataset.
- Parameters
dataset – dataset to evaluate.
- Returns
mean r2_score.
Module contents
__init__.py