class_docstr: Abstract base class for deep learning networks using torch.nn.
class_docstr_tok: ["Abstract","base","class","for","deep","learning","networks","using","torch.nn","."]
docstr: Fit the network.
  
  Changes to state:
      writes to self._network.state_dict
  
  Parameters
  ----------
  X : iterable-style or map-style dataset
      see (https://pytorch.org/docs/stable/data.html) for more information
docstr_tok: ["Fit","the","network",".","Changes","to","state",":","writes","to","self._network.state_dict","Parameters","--","--","--","--","--","X",":","iterable-style","or","map-style","dataset","see","(","https",":","\/\/pytorch.org\/docs\/stable\/data.html",")","for","more","information"]
code: def _fit(self, y, fh, X=None):
      """Fit the network.
  
      Changes to state:
          writes to self._network.state_dict
  
      Parameters
      ----------
      X : iterable-style or map-style dataset
          see (https://pytorch.org/docs/stable/data.html) for more information
      """
      from sktime.forecasting.base import ForecastingHorizon
  
      # save fh and y for prediction later
      if fh.is_relative:
          self._fh = fh
      else:
          fh = fh.to_relative(self.cutoff)
          self._fh = fh
  
      self._y = y
  
      if type(fh) is ForecastingHorizon:
          self.network = self._build_network(fh._values[-1])
      else:
          self.network = self._build_network(fh)
  
      if self.criterion:
          if self.criterion in self.criterions.keys():
              if self.criterion_kwargs:
                  self._criterion = self.criterions[self.criterion](
                      **self.criterion_kwargs
                  )
              else:
                  self._criterion = self.criterions[self.criterion]()
          else:
              raise TypeError(
                  f"Please pass one of {self.criterions.keys()} for `criterion`."
              )
      else:
          # default criterion
          self._criterion = torch.nn.MSELoss()
  
      if self.optimizer:
          if self.optimizer in self.optimizers.keys():
              if self.optimizer_kwargs:
                  self._optimizer = self.optimizers[self.optimizer](
                      self.network.parameters(),
                      lr=self.lr,
                      **self.optimizer_kwargs,
                  )
              else:
                  self._optimizer = self.optimizers[self.optimizer](
                      self.network.parameters(), lr=self.lr
                  )
          else:
              raise TypeError(
                  f"Please pass one of {self.optimizers.keys()} for `optimizer`."
              )
      else:
          # default optimizer
          self._optimizer = torch.optim.Adam(
              self.network.parameters(), lr=self.lr
          )
  
      dataloader = self.build_pytorch_train_dataloader(y)
      self.network.train()
  
      for _ in range(self.num_epochs):
          for x, y in dataloader:
              y_pred = self.network(x)
              loss = self._criterion(y_pred, y)
              self._optimizer.zero_grad()
              loss.backward()
              self._optimizer.step()
  
imports: from abc import ABC, abstractmethod
  import numpy
  import pandas
  from sktime.base import BaseObject
  from sktime.forecasting.base import BaseForecaster
  from sktime.utils.validation._dependencies import _check_soft_dependencies
label_desc: Use image node_id 2 for calling the BaseDeepNetworkPyTorch obj's underlying member method code with example usage: obj._fit(y, fh, X) without return types