Repository: sktime/sktime

Issue:
[ENH] Make BaseClassifier abstract with ABC
**Is your feature request related to a problem? Please describe.**

both _fit and _predict should be properly abstract using ABC, rather than just raising an error. 

This cannot be done until all classifiers conform to _fit/fit model. This is linked here

- #1609
- #1608
- #1607
- #1606

this is complicated by the fact that it seems TimeSeriesForestClassifier is used in annotation, benchmarking, forecasting, series_as_features, transformations and utils.


Discussion:
indeed - I think there is a more general question about use of abc throughout sktime.
I'm in favour, although as you correctly identify, various refactors need to be completed first.

May I change this to "use abc for sktime base classes" in general?
Yes please do, ABC is already used in series as features and clustering, so we may as well encourage its usage everywhere I think
It seems, that all the blocking issues are solve. I can take  a look at this, but would need some more information to understand the  requirements. Any help would be appreciated @TonyBagnall @fkiraly :slightly_smiling_face:   
well - I there is a more serious design issue in the background.

We need to work out how we would be using `abc`, which classes inherit from it.
I would be very reluctant to do this only for classifiers, or without a proper design worked out.

We must avoid pattern divergence between the modules, and ad-hoc hacks to our framework, in my opinion.

I've opened an issue here: https://github.com/alan-turing-institute/sktime/issues/1923

Resolving patch:
diff --git a/sktime/classification/base.py b/sktime/classification/base.py
--- a/sktime/classification/base.py
+++ b/sktime/classification/base.py
@@ -26,6 +26,7 @@ class name: BaseClassifier
 __author__ = ["mloning", "fkiraly", "TonyBagnall", "MatthewMiddlehurst"]
 
 import time
+from abc import ABC, abstractmethod
 
 import numpy as np
 import pandas as pd
@@ -35,13 +36,12 @@ class name: BaseClassifier
 from sktime.utils.validation import check_n_jobs
 
 
-class BaseClassifier(BaseEstimator):
+class BaseClassifier(BaseEstimator, ABC):
     """Abstract base class for time series classifiers.
 
     The base classifier specifies the methods and method signatures that all
     classifiers have to implement. Attributes with a underscore suffix are set in the
     method fit.
-    #TODO: Make _fit and _predict abstract
 
     Parameters
     ----------
@@ -241,6 +241,7 @@ def _check_convert_X_for_predict(self, X):
 
         return X
 
+    @abstractmethod
     def _fit(self, X, y):
         """Fit time series classifier to training data.
 
@@ -267,10 +268,9 @@ def _fit(self, X, y):
         Changes state by creating a fitted model that updates attributes
         ending in "_" and sets is_fitted flag to True.
         """
-        raise NotImplementedError(
-            "_fit is a protected abstract method, it must be implemented."
-        )
+        ...
 
+    @abstractmethod
     def _predict(self, X) -> np.ndarray:
         """Predicts labels for sequences in X.
 
@@ -291,9 +291,7 @@ def _predict(self, X) -> np.ndarray:
         y : 1D np.array of int, of shape [n_instances] - predicted class labels
             indices correspond to instance indices in X
         """
-        raise NotImplementedError(
-            "_predict is a protected abstract method, it must be implemented."
-        )
+        ...
 
     def _predict_proba(self, X) -> np.ndarray:
         """Predicts labels probabilities for sequences in X.


Test patch: