dsipts.TimeSeries¶
- class dsipts.TimeSeries(name: str, stacked: bool = False)¶
Class for generating time series object. If you don’t have any time series you can build one fake timeseries using some helping classes (Categorical for instance).
- Parameters:
name (str) – name of the series
stacked (bool) – if true it is a stacked model
- Usage:
For example we can generate a toy timeseries:
add a multiplicative categorical feature (weekly)
>>> settimana = Categorical('settimanale',1,[1,1,1,1,1,1,1],7,'multiplicative',[0.9,0.8,0.7,0.6,0.5,0.99,0.99])
an additive montly feature (here a year is composed by 5 months)
>>> mese = Categorical('mensile',1,[31,28,20,10,33],5,'additive',[10,20,-10,20,0])
a spotted categorical variable that happens every 100 days and lasts 1 day
>>> spot = Categorical('spot',100,[7],1,'additive',[10])
>>> ts = TimeSeries('prova')
>>> ts.generate_signal(length = 5000,categorical_variables = [settimana,mese,spot],noise_mean=1,type=0) ##we can add also noise
>>> ts.plot()
- __init__(name: str, stacked: bool = False)¶
Class for generating time series object. If you don’t have any time series you can build one fake timeseries using some helping classes (Categorical for instance).
- Parameters:
name (str) – name of the series
stacked (bool) – if true it is a stacked model
- Usage:
For example we can generate a toy timeseries:
add a multiplicative categorical feature (weekly)
>>> settimana = Categorical('settimanale',1,[1,1,1,1,1,1,1],7,'multiplicative',[0.9,0.8,0.7,0.6,0.5,0.99,0.99])
an additive montly feature (here a year is composed by 5 months)
>>> mese = Categorical('mensile',1,[31,28,20,10,33],5,'additive',[10,20,-10,20,0])
a spotted categorical variable that happens every 100 days and lasts 1 day
>>> spot = Categorical('spot',100,[7],1,'additive',[10])
>>> ts = TimeSeries('prova')
>>> ts.generate_signal(length = 5000,categorical_variables = [settimana,mese,spot],noise_mean=1,type=0) ##we can add also noise
>>> ts.plot()
Methods
__init__
(name[, stacked])Class for generating time series object.
create_data_loader
(data, past_steps, ...[, ...])Create the dataset for the training/inference step
enrich
(dataset, columns)generate_signal
([length, ...])This will generate a syntetic signal with a selected length, a noise level and some categorical variables.
inference
([batch_size, num_workers, ...])similar to inference_on_set only change is split_params that must contain this keys but using the default can be sufficient: 'past_steps','future_steps','shift','keep_entire_seq_while_shifting','starting_point'
inference_on_set
([batch_size, num_workers, ...])This function allows to get the prediction on a particular set (train, test or validation).
load
(model, filename[, load_last, dirpath, ...])Load a saved model
load_signal
(data[, enrich_cat, ...])This is a crucial point in the data structure. We expect here to have a dataset with time as timestamp.
plot
()Easy way to control the loaded data :returns: figure of the target variables :rtype: plotly.graph_objects._figure.Figure
save
(filename)save the timeseries object
set_model
(model[, config, custom_init])Set the model to train
set_verbose
(verbose)split_for_train
([perc_train, perc_valid, ...])Split the data and create the datasets.
train_model
(dirpath, split_params[, ...])Train the model