class_docstr: Defines Temporal Fusion Transformer.
  
  Attributes:
    name: Name of model
    time_steps: Total number of input time steps per forecast date (i.e. Width
      of Temporal fusion decoder N)
    input_size: Total number of inputs
    output_size: Total number of outputs
    category_counts: Number of categories per categorical variable
    n_multiprocessing_workers: Number of workers to use for parallel
      computations
    column_definition: List of tuples of (string, DataType, InputType) that
      define each column
    quantiles: Quantiles to forecast for TFT
    use_cudnn: Whether to use Keras CuDNNLSTM or standard LSTM layers
    hidden_layer_size: Internal state size of TFT
    dropout_rate: Dropout discard rate
    max_gradient_norm: Maximum norm for gradient clipping
    learning_rate: Initial learning rate of ADAM optimizer
    minibatch_size: Size of minibatches for training
    num_epochs: Maximum number of epochs for training
    early_stopping_patience: Maximum number of iterations of non-improvement
      before early stopping kicks in
    num_encoder_steps: Size of LSTM encoder -- i.e. number of past time steps
      before forecast date to use
    num_stacks: Number of self-attention layers to apply (default is 1 for basic
      TFT)
    num_heads: Number of heads for interpretable mulit-head attention
    model: Keras model for TFT
class_docstr_tok: ["Defines","Temporal","Fusion","Transformer",".","Attributes",":","name",":","Name","of","model","time_steps",":","Total","number","of","input","time","steps","per","forecast","date","(","i.e",".","Width","of","Temporal","fusion","decoder","N",")","input_size",":","Total","number","of","inputs","output_size",":","Total","number","of","outputs","category_counts",":","Number","of","categories","per","categorical","variable","n_multiprocessing_workers",":","Number","of","workers","to","use","for","parallel","computations","column_definition",":","List","of","tuples","of","(","string",",","DataType",",","InputType",")","that","define","each","column","quantiles",":","Quantiles","to","forecast","for","TFT","use_cudnn",":","Whether","to","use","Keras","CuDNNLSTM","or","standard","LSTM","layers","hidden_layer_size",":","Internal","state","size","of","TFT","dropout_rate",":","Dropout","discard","rate","max_gradient_norm",":","Maximum","norm","for","gradient","clipping","learning_rate",":","Initial","learning","rate","of","ADAM","optimizer","minibatch_size",":","Size","of","minibatches","for","training","num_epochs",":","Maximum","number","of","epochs","for","training","early_stopping_patience",":","Maximum","number","of","iterations","of","non-improvement","before","early","stopping","kicks","in","num_encoder_steps",":","Size","of","LSTM","encoder","--","i.e",".","number","of","past","time","steps","before","forecast","date","to","use","num_stacks",":","Number","of","self-attention","layers","to","apply","(","default","is","1","for","basic","TFT",")","num_heads",":","Number","of","heads","for","interpretable","mulit-head","attention","model",":","Keras","model","for","TFT"]
docstr: Fits deep neural network for given training and validation data.
  
  Args:
    train_df: DataFrame for training data
    valid_df: DataFrame for validation data
docstr_tok: ["Fits","deep","neural","network","for","given","training","and","validation","data",".","Args",":","train_df",":","DataFrame","for","training","data","valid_df",":","DataFrame","for","validation","data"]
code: def fit(self, train_df=None, valid_df=None):
      """Fits deep neural network for given training and validation data.
  
      Args:
        train_df: DataFrame for training data
        valid_df: DataFrame for validation data
      """
  
      print("*** Fitting {} ***".format(self.name))
  
      # Add relevant callbacks
      callbacks = [
          tf.keras.callbacks.EarlyStopping(
              monitor="val_loss",
              patience=self.early_stopping_patience,
              min_delta=1e-4,
          ),
          tf.keras.callbacks.ModelCheckpoint(
              filepath=self.get_keras_saved_path(self._temp_folder),
              monitor="val_loss",
              save_best_only=True,
              save_weights_only=True,
          ),
          tf.keras.callbacks.TerminateOnNaN(),
      ]
  
      print("Getting batched_data")
      if train_df is None:
          print("Using cached training data")
          train_data = TFTDataCache.get("train")
      else:
          train_data = self._batch_data(train_df)
  
      if valid_df is None:
          print("Using cached validation data")
          valid_data = TFTDataCache.get("valid")
      else:
          valid_data = self._batch_data(valid_df)
  
      print("Using keras standard fit")
  
      def _unpack(data):
          return (
              data["inputs"],
              data["outputs"],
              self._get_active_locations(data["active_entries"]),
          )
  
      # Unpack without sample weights
      data, labels, active_flags = _unpack(train_data)
      val_data, val_labels, val_flags = _unpack(valid_data)
  
      all_callbacks = callbacks
  
      self.model.fit(
          x=data,
          y=np.concatenate([labels, labels, labels], axis=-1),
          sample_weight=active_flags,
          epochs=self.num_epochs,
          batch_size=self.minibatch_size,
          validation_data=(
              val_data,
              np.concatenate(
                  [val_labels, val_labels, val_labels], axis=-1
              ),
              val_flags,
          ),
          callbacks=all_callbacks,
          shuffle=True,
          use_multiprocessing=True,
          workers=self.n_multiprocessing_workers,
      )
  
      # Load best checkpoint again
      tmp_checkpont = self.get_keras_saved_path(self._temp_folder)
      if os.path.exists(tmp_checkpont):
          self.load(self._temp_folder, use_keras_loadings=True)
  
      else:
          print(
              "Cannot load from {}, skipping ...".format(
                  self._temp_folder
              )
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import gc
  import json
  import os
  import shutil
  import data_formatters.base
  import libs.utils
  import numpy
  import pandas
  import tensorflow
label_desc: Use image node_id 11 for calling the TemporalFusionTransformer obj's underlying member method code with example usage: obj.fit(train_df, valid_df) and returns: data,  data,  self