Repository: sktime/sktime

Issue:
[ENH] `num_epochs` should be renamed to `n_epochs` in `SimpleRNNClassifier` and `SimpleRNNRegressor`
Currently, we take `n_epochs` in all other estimators within the `deep_learning` subpackage with the exception of `SimpleRNNClassifier`. This inconsistency should be addressed with a deprecation of the usage of `num_epochs` in favor of `n_epochs`.


Discussion:
agree.

Not a bug though, I would classify this as an enhancement.

Plus, we should do the same for the regressor.
Is this issue open, Can you assign it to me ?
Done! Welcome to sktime :)

Feel free to ask for help if you feel stuck. Thanks

Resolving patch:
diff --git a/sktime/classification/deep_learning/rnn.py b/sktime/classification/deep_learning/rnn.py
--- a/sktime/classification/deep_learning/rnn.py
+++ b/sktime/classification/deep_learning/rnn.py
@@ -11,8 +11,13 @@
 from sktime.classification.deep_learning.base import BaseDeepClassifier
 from sktime.networks.rnn import RNNNetwork
 from sktime.utils.validation._dependencies import _check_dl_dependencies
+from sktime.utils.warnings import warn
 
 
+# todo: 0.26.0 - please remove num_epochs parameter and related logic,
+# because parameter num_epochs usage is deprecated and will be renamed
+# to n_epochs.  Also n_epochs should be moved to become the first
+# argument in the __init__ and super().__init__.
 class SimpleRNNClassifier(BaseDeepClassifier):
     """Simple recurrent neural network.
 
@@ -51,7 +56,7 @@ class SimpleRNNClassifier(BaseDeepClassifier):
 
     def __init__(
         self,
-        num_epochs=100,
+        num_epochs=None,
         batch_size=1,
         units=6,
         callbacks=None,
@@ -63,10 +68,26 @@ def __init__(
         activation="sigmoid",
         use_bias=True,
         optimizer=None,
+        n_epochs=100,
     ):
         _check_dl_dependencies(severity="error")
         super().__init__()
+        # todo: 0.26.0 - remove this, replace by
+        # self._n_epochs = n_epochs
+        # Deprecated Parameter Handling
+        if num_epochs is not None:
+            warn(
+                "In SimpleRNNClassifier, the parameter 'num_epochs' is deprecated "
+                "and will be removed in v0.26.0. It will be renamed to n_epochs. "
+                "To avoid this warning, update your code to use 'n_epochs'. ",
+                DeprecationWarning,
+                stacklevel=2,
+            )
+            self._n_epochs = num_epochs
+        else:
+            self._n_epochs = n_epochs
         self.num_epochs = num_epochs
+        # end remove
         self.batch_size = batch_size
         self.verbose = verbose
         self.units = units
@@ -80,6 +101,7 @@ def __init__(
         self.optimizer = optimizer
         self.history = None
         self._network = RNNNetwork(random_state=random_state, units=units)
+        self.n_epochs = n_epochs
 
     def build_model(self, input_shape, n_classes, **kwargs):
         """Construct a compiled, un-trained, keras model that is ready for training.
@@ -189,7 +211,7 @@ def _fit(self, X, y):
             X,
             y_onehot,
             batch_size=self.batch_size,
-            epochs=self.num_epochs,
+            epochs=self._n_epochs,
             verbose=self.verbose,
             callbacks=self.callbacks_,
         )
@@ -218,7 +240,7 @@ def get_test_params(cls, parameter_set="default"):
         """
         params1 = {}
         params2 = {
-            "num_epochs": 50,
+            "n_epochs": 50,
             "batch_size": 2,
             "units": 5,
             "use_bias": False,
diff --git a/sktime/regression/deep_learning/rnn.py b/sktime/regression/deep_learning/rnn.py
--- a/sktime/regression/deep_learning/rnn.py
+++ b/sktime/regression/deep_learning/rnn.py
@@ -11,8 +11,13 @@
 from sktime.networks.rnn import RNNNetwork
 from sktime.regression.deep_learning.base import BaseDeepRegressor
 from sktime.utils.validation._dependencies import _check_dl_dependencies
+from sktime.utils.warnings import warn
 
 
+# todo: 0.26.0 - please remove num_epochs parameter and related logic,
+# because parameter num_epochs usage is deprecated and will be renamed
+# to n_epochs.  Also n_epochs should be moved to become the first
+# argument in the __init__ and super().__init__.
 class SimpleRNNRegressor(BaseDeepRegressor):
     """Simple recurrent neural network.
 
@@ -51,7 +56,7 @@ class SimpleRNNRegressor(BaseDeepRegressor):
 
     def __init__(
         self,
-        num_epochs=100,
+        num_epochs=None,
         batch_size=1,
         units=6,
         callbacks=None,
@@ -63,10 +68,26 @@ def __init__(
         activation="linear",
         use_bias=True,
         optimizer=None,
+        n_epochs=100,
     ):
         _check_dl_dependencies(severity="error")
         super().__init__()
+        # todo: 0.26.0 - remove this, replace by
+        # self._n_epochs = n_epochs
+        # Deprecated Parameter Handling
+        if num_epochs is not None:
+            warn(
+                "In SimpleRNNRegressor, the parameter 'num_epochs' is deprecated "
+                "and will be removed in v0.26.0. It will be renamed to n_epochs. "
+                "To avoid this warning, update your code to use 'n_epochs'. ",
+                DeprecationWarning,
+                stacklevel=2,
+            )
+            self._n_epochs = num_epochs
+        else:
+            self._n_epochs = n_epochs
         self.num_epochs = num_epochs
+        # end remove
         self.batch_size = batch_size
         self.verbose = verbose
         self.units = units
@@ -80,6 +101,7 @@ def __init__(
         self.optimizer = optimizer
         self.history = None
         self._network = RNNNetwork(random_state=random_state, units=units)
+        self.n_epochs = n_epochs
 
     def build_model(self, input_shape, **kwargs):
         """Construct a compiled, un-trained, keras model that is ready for training.
@@ -183,7 +205,7 @@ def _fit(self, X, y):
             X,
             y,
             batch_size=self.batch_size,
-            epochs=self.num_epochs,
+            epochs=self._n_epochs,
             verbose=self.verbose,
             callbacks=self.callbacks_,
         )
@@ -212,7 +234,7 @@ def get_test_params(cls, parameter_set="default"):
         """
         params1 = {}
         params2 = {
-            "num_epochs": 50,
+            "n_epochs": 50,
             "batch_size": 2,
             "units": 5,
             "use_bias": False,


Test patch: