Repository: Lightning-Universe/lightning-flash

Issue:
Add a tabular_forecasting example



Discussion:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


Resolving patch:
diff --git a/flash/tabular/forecasting/data.py b/flash/tabular/forecasting/data.py
--- a/flash/tabular/forecasting/data.py
+++ b/flash/tabular/forecasting/data.py
@@ -125,12 +125,14 @@ def load_state_dict(cls, state_dict: Dict[str, Any], strict: bool = True) -> "Pr
 
 
 class TabularForecastingData(DataModule):
-    """Data module for tabular tasks."""
+    """Data module for the tabular forecasting task."""
 
     preprocess_cls = TabularForecastingPreprocess
 
     @property
     def parameters(self) -> Optional[Dict[str, Any]]:
+        """The parameters dictionary from the ``TimeSeriesDataSet`` object created from the train data when
+        constructing the ``TabularForecastingData`` object."""
         return getattr(self.train_dataset, "parameters", None)
 
     @classmethod
@@ -155,12 +157,24 @@ def from_data_frame(
         num_workers: Optional[int] = None,
         **preprocess_kwargs: Any,
     ):
-        """Creates a :class:`~flash.tabular.data.TabularClassificationData` object from the given data frames.
+        """Creates a :class:`~flash.tabular.forecasting.data.TabularForecastingData` object from the given data
+        frames.
+
+        .. note::
+
+            The ``time_idx``, ``target``, and ``group_ids`` do not need to be provided if ``parameters`` are passed
+            instead. These can be obtained from the
+            :attr:`~flash.tabular.forecasting.data.TabularForecastingData.parameters` attribute of the
+            :class:`~flash.tabular.forecasting.data.TabularForecastingData` object that contains your training data.
 
         Args:
-            group_ids:
-            target:
             time_idx:
+            target: Column denoting the target or list of columns denoting the target.
+            group_ids: 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 column that is
+                constant.
+            parameters: Parameters to use for the timeseries if ``time_idx``, ``target``, and ``group_ids`` are not
+                provided (e.g. when loading data for inference or validation).
             train_data_frame: The pandas ``DataFrame`` containing the training data.
             val_data_frame: The pandas ``DataFrame`` containing the validation data.
             test_data_frame: The pandas ``DataFrame`` containing the testing data.
@@ -189,10 +203,10 @@ def from_data_frame(
 
         Examples::
 
-            data_module = TabularClassificationData.from_data_frame(
-                "categorical_input",
-                "numerical_input",
-                "target",
+            data_module = TabularForecastingData.from_data_frame(
+                time_idx="time_idx",
+                target="value",
+                group_ids=["series"],
                 train_data_frame=train_data,
             )
         """
diff --git a/flash_examples/integrations/pytorch_forecasting/tabular_forecasting_interpretable.py b/flash_examples/integrations/pytorch_forecasting/tabular_forecasting_interpretable.py
--- a/flash_examples/integrations/pytorch_forecasting/tabular_forecasting_interpretable.py
+++ b/flash_examples/integrations/pytorch_forecasting/tabular_forecasting_interpretable.py
@@ -59,16 +59,12 @@
 predictions = model.predict(data)
 print(predictions)
 
-# Convert predictions
+# Plot with PyTorch Forecasting!
 predictions, inputs = convert_predictions(predictions)
 
-# Plot predictions
-for idx in range(10):  # plot 10 examples
-    model.pytorch_forecasting_model.plot_prediction(inputs, predictions, idx=idx, add_loss_to_title=True)
+fig, axs = plt.subplots(2, 3, sharex="col")
 
-# Plot interpretation
-for idx in range(10):  # plot 10 examples
-    model.pytorch_forecasting_model.plot_interpretation(inputs, predictions, idx=idx)
+for idx in range(3):
+    model.pytorch_forecasting_model.plot_interpretation(inputs, predictions, idx=idx, ax=[axs[0][idx], axs[1][idx]])
 
-# Show the plots!
 plt.show()


Test patch: