tempor.data.dataset module¶
Module defining the TemporAI dataset concept in BaseDataset and its derived classes.
-
tempor.data.dataset.EXCEPTION_MESSAGES =
_ExceptionMessages()¶ Reusable error messages for the module.
-
class tempor.data.dataset.BaseDataset(time_series: DataFrame | ndarray, *, static: DataFrame | ndarray | None =
None, targets: DataFrame | ndarray | None =None, treatments: DataFrame | ndarray | None =None, **kwargs: Any)[source]¶ Bases:
ABCAbstract base class representing a dataset used by TemporAI.
Initialize one of its derived classes (e.g.
OneOffPredictionDataset,TimeToEventAnalysisDatasetetc.) depending on the type of task.See also tutorial
tutorials/tutorial01_data_format.ipynbfor examples of use.- Parameters:¶
- time_series : data_typing.DataContainer¶
Data representing time series covariates of the samples. Will be initialized as
TimeSeriesSamples.- static : Optional[data_typing.DataContainer], optional¶
Data representing static covariates of the samples. Will be initialized as
StaticSamples. Defaults toNone.- targets : Optional[data_typing.DataContainer], optional¶
Data representing target (outcome) feature(s) of the samples. Will be initialized as
{TimeSeries,Static,Event}Samplesdepending on problem setting in the derived class. Defaults toNone.- treatments : Optional[data_typing.DataContainer], optional¶
Data representing treatment (intervention) feature(s) of the samples. Will be initialized as
{TimeSeries,Static,Event}Samplesdepending on problem setting in the derived class. Defaults toNone.- **kwargs : Any
Additional keyword arguments to be passed to the derived class’s
_init_predictivemethod.
- predictive : PredictiveTaskData | None¶
- property has_predictive_data : bool¶
A property returning whether the dataset has predictive data (
targetsortreatments).
- property predictive_task : PredictiveTask | None¶
A property returning the predictive task of the dataset (or
None).- Returns:¶
The predictive task of the dataset.
- Return type:¶
Union[data_typing.PredictiveTask, None]
- property time_series : TimeSeriesSamplesBase¶
The property containing the time series covariates of the dataset.
- property static : StaticSamplesBase | None¶
The property containing the static covariates of the dataset.
- Returns:¶
The static covariates of the dataset.
- Return type:¶
Optional[samples.StaticSamplesBase]
- abstract property fit_ready : bool¶
Returns whether the
BaseDatasetis in a state ready to befiton.
-
train_test_split(*, test_size: float | None =
None, train_size: float | None =None, random_state: int | RandomState | None =None, shuffle: bool =True, stratify: Any | None =None) tuple[Self, Self][source]¶ Split
Datasetinto train and test sets.The arguments
test_size…stratifyare passed tosklearn.model_selection.train_test_splitto generate the split.- Parameters:¶
- test_size : Optional[float], optional¶
Passed to
sklearn.model_selection.train_test_split. Defaults toNone.- train_size : Optional[float], optional¶
Passed to
sklearn.model_selection.train_test_split. Defaults toNone.- random_state : Union[int, np.random.RandomState, None], optional¶
Passed to
sklearn.model_selection.train_test_split. Defaults toNone.- shuffle : bool, optional¶
Passed to
sklearn.model_selection.train_test_split. Defaults toTrue.- stratify : Any, optional¶
Passed to
sklearn.model_selection.train_test_split. Defaults toNone.
- Returns:¶
The split tuple
(dataset_train, dataset_test).- Return type:¶
Tuple[Self, Self]
- split(splitter: KFold | StratifiedKFold, **kwargs: Any) Generator[tuple[Self, Self], None, None][source]¶
Generate dataset splits according to the scikit-learn
splitter(Splitter). Thekwargsare passed to the underlying splitter’ssplitmethod.Example
>>> from sklearn.model_selection import KFold >>> from tempor import plugin_loader >>> data = plugin_loader.get("prediction.one_off.sine", plugin_type="datasource").load() >>> kfold = KFold(n_splits=5) >>> len([(data_train, data_test) for (data_train, data_test) in data.split(splitter=kfold)]) 5
-
class tempor.data.dataset.CovariatesDataset(time_series: DataFrame | ndarray, *, static: DataFrame | ndarray | None =
None, targets: DataFrame | ndarray | None =None, treatments: DataFrame | ndarray | None =None, **kwargs: Any)[source]¶ Bases:
BaseDatasetA
BaseDatasetsubclass for a dataset that does not contain any predictive data (targetsortreatments).- predictive : PredictiveTaskData | None¶
-
class tempor.data.dataset.PredictiveDataset(time_series: DataFrame | ndarray, *, targets: DataFrame | ndarray | None, static: DataFrame | ndarray | None =
None, treatments: DataFrame | ndarray | None =None, **kwargs: Any)[source]¶ Bases:
BaseDatasetA
BaseDatasetsubclass for a dataset that can contain predictive data (targetsortreatments).This is an abstract class, to be derived from for different predictive task -specific
Datasets.- predictive : PredictiveTaskData¶
- abstract property predict_ready : bool¶
Returns whether the
PredictiveDatasetis in a state ready to bepredicted on.
-
class tempor.data.dataset.OneOffPredictionDataset(time_series: DataFrame | ndarray, *, targets: DataFrame | ndarray | None, static: DataFrame | ndarray | None =
None, treatments: DataFrame | ndarray | None =None, **kwargs: Any)[source]¶ Bases:
PredictiveDatasetA
PredictiveDatasetsubclass for the one-off prediction problem setting, seeBaseDatasetdocs.In this setting:
targetsare required for fitting, will be initialized asStaticSamples.- predictive : OneOffPredictionTaskData¶
-
class tempor.data.dataset.TemporalPredictionDataset(time_series: DataFrame | ndarray, *, targets: DataFrame | ndarray | None, static: DataFrame | ndarray | None =
None, treatments: DataFrame | ndarray | None =None, **kwargs: Any)[source]¶ Bases:
PredictiveDatasetA
PredictiveDatasetsubclass for the temporal prediction problem setting, seeBaseDatasetdocs.In this setting:
targetsare required for fitting, will be initialized asTimeSeriesSamples.- predictive : TemporalPredictionTaskData¶
-
class tempor.data.dataset.TimeToEventAnalysisDataset(time_series: DataFrame | ndarray, *, targets: DataFrame | ndarray | None, static: DataFrame | ndarray | None =
None, treatments: DataFrame | ndarray | None =None, **kwargs: Any)[source]¶ Bases:
PredictiveDatasetA
PredictiveDatasetsubclass for the time-to-event analysis problem setting, seeBaseDatasetdocs.In this setting:
targetsare required for fitting, will be initialized asEventSamples.- predictive : TimeToEventAnalysisTaskData¶
-
class tempor.data.dataset.OneOffTreatmentEffectsDataset(time_series: DataFrame | ndarray, *, targets: DataFrame | ndarray | None, treatments: DataFrame | ndarray, static: DataFrame | ndarray | None =
None, **kwargs: Any)[source]¶ Bases:
PredictiveDatasetA
PredictiveDatasetsubclass for the one-off treatment effects problem setting, seeBaseDatasetdocs.In this setting:
targetsare required for fitting, will be initialized asTimeSeriesSamples;treatmentsare required for both fitting and prediction, will be initialized asEventSamples.- predictive : OneOffTreatmentEffectsTaskData¶
-
class tempor.data.dataset.TemporalTreatmentEffectsDataset(time_series: DataFrame | ndarray, *, targets: DataFrame | ndarray | None, treatments: DataFrame | ndarray, static: DataFrame | ndarray | None =
None, **kwargs: Any)[source]¶ Bases:
PredictiveDatasetA
PredictiveDatasetsubclass for the temporal treatment effects problem setting, seeBaseDatasetdocs.In this setting:
targetsare required for fitting, will be initialized asTimeSeriesSamples;treatmentsare required for both fitting and prediction, will be initialized asTimeSeriesSamples.- predictive : TemporalTreatmentEffectsTaskData¶