TabularForecastingData¶
- class flash.tabular.forecasting.data.TabularForecastingData(train_input=None, val_input=None, test_input=None, predict_input=None, data_fetcher=None, transform=<class 'flash.core.data.io.input_transform.InputTransform'>, transform_kwargs=None, val_split=None, batch_size=None, num_workers=0, sampler=None, pin_memory=True, persistent_workers=False)[source]¶
The
TabularForecastingData
class is aDataModule
with a set of classmethods for loading data for tabular forecasting.- classmethod from_data_frame(time_idx=None, target=None, group_ids=None, parameters=None, train_data_frame=None, val_data_frame=None, test_data_frame=None, predict_data_frame=None, input_cls=<class 'flash.tabular.forecasting.input.TabularForecastingDataFrameInput'>, transform=<class 'flash.core.data.io.input_transform.InputTransform'>, transform_kwargs=None, data_fetcher=None, val_split=None, batch_size=None, num_workers=0, sampler=None, pin_memory=True, persistent_workers=True, **input_kwargs)[source]¶
Creates a
TabularForecastingData
object from the given data frames.Note
The
time_idx
,target
, andgroup_ids
do not need to be provided ifparameters
are passed instead. These can be obtained from theparameters
attribute of theTabularForecastingData
object that contains your training data.To learn how to customize the transforms applied for each stage, read our customizing transforms guide.
- Parameters
time_idx¶ (
Optional
[str
]) – Column denoting the time index of each observation.target¶ (
Union
[str
,List
[str
],None
]) – Column denoting the target or list of columns denoting the target.group_ids¶ (
Optional
[List
[str
]]) – List of column names identifying a time series. This means that the group_ids identify a sample together with the time_idx. If you have only one timeseries, set this to the name of a column that is constant.parameters¶ (
Optional
[Dict
[str
,Any
]]) – Parameters to use for the timeseries iftime_idx
,target
, andgroup_ids
are not provided (e.g. when loading data for inference or validation).train_data_frame¶ (
Optional
[DataFrame
]) – The pandas DataFrame to use when training.val_data_frame¶ (
Optional
[DataFrame
]) – The pandas DataFrame to use when validating.test_data_frame¶ (
Optional
[DataFrame
]) – The pandas DataFrame to use when testing.predict_data_frame¶ (
Optional
[DataFrame
]) – The pandas DataFrame to use when predicting.input_cls¶ (
Type
[Input
]) – TheInput
type to use for loading the data.transform¶ (
TypeVar
(INPUT_TRANSFORM_TYPE
,Type
[flash.core.data.io.input_transform.InputTransform],Callable
,Tuple
[Union
[StrEnum
,str
],Dict
[str
,Any
]],Union
[StrEnum
,str
],None
)) – TheInputTransform
type to use.transform_kwargs¶ (
Optional
[Dict
]) – Dict of keyword arguments to be provided when instantiating the transforms.input_kwargs¶ (
Any
) – Additional keyword arguments to be used when creating the TimeSeriesDataset.
- Return type
- Returns
The constructed
TabularForecastingData
.
Examples
We have a DataFrame data with the following contents:
>>> data.head(3) series time_idx value 0 0 0 -0.000000 1 0 1 0.141552 2 0 2 0.232782
>>> from pandas import DataFrame >>> from flash import Trainer >>> from flash.tabular import TabularForecaster, TabularForecastingData >>> datamodule = TabularForecastingData.from_data_frame( ... "time_idx", ... "value", ... ["series"], ... train_data_frame=data, ... predict_data_frame=DataFrame.from_dict( ... { ... "time_idx": list(range(50)), ... "value": [0.0] * 50, ... "series": [0] * 50, ... } ... ), ... time_varying_unknown_reals=["value"], ... max_encoder_length=30, ... max_prediction_length=20, ... batch_size=32, ... ) >>> model = TabularForecaster( ... datamodule.parameters, ... backbone="n_beats", ... backbone_kwargs={"widths": [16, 256]}, ... ) >>> trainer = Trainer(fast_dev_run=True) >>> trainer.fit(model, datamodule=datamodule) Training... >>> trainer.predict(model, datamodule=datamodule) Predicting...
- input_transform_cls¶