Repository: sktime/sktime

Issue:
[BUG] `StatsForecastBackAdapter` incorrectly passes `1-coverage` as `StatsForecast` level
**Describe the bug**

I'm not 100% sure if this is just working as intended since it's pretty explicit in the code (see [here](https://github.com/sktime/sktime/blob/df21a0c0275ebf28deb30efac5d469c9f0d178e3/sktime/forecasting/base/adapters/_generalised_statsforecast.py#L507) and [here](https://github.com/sktime/sktime/blob/df21a0c0275ebf28deb30efac5d469c9f0d178e3/sktime/forecasting/base/adapters/_generalised_statsforecast.py#L535)), but it seems the `StatsForecastBackAdapter` is taking the coverage argument passed by the user and passing it to StatsForecast as `level=1-coverage`. So doing something like this:

```python
import pandas as pd

from sktime.datasets import load_airline
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.statsforecast import StatsForecastMSTL

y = load_airline()

model = StatsForecastMSTL(season_length=[12])
model.fit(y)
fh_index = pd.PeriodIndex(pd.date_range("1961-01", periods=36, freq="M"))
fh = ForecastingHorizon(fh_index, is_relative=False)
model.predict_interval(fh, coverage=0.95)
```

actually passes `level=[5.0]` to StatsForecast.

**To Reproduce**

See failing test case added to [this fork](https://github.com/sktime/sktime/compare/main...sd2k:sktime:statsforecast-mstl-level-coverage-error)

**Expected behavior**

I _think_ that the level should be passed through as-is, but I may be missing something 🤔 

**Additional context**

N/A

**Versions**
<details>
System:
    python: 3.11.1 (main, Dec 28 2022, 11:29:27) [Clang 14.0.0 (clang-1400.0.29.202)]
executable: /Users/ben/.pyenv/versions/sktime/bin/python
   machine: macOS-14.1.1-arm64-arm-64bit

Python dependencies:
          pip: 22.3.1
       sktime: 0.24.1
      sklearn: 1.3.2
       skbase: 0.6.1
        numpy: 1.26.2
        scipy: 1.11.4
       pandas: 2.1.3
   matplotlib: 3.8.2
       joblib: 1.3.2
        numba: 0.58.1
  statsmodels: 0.14.0
     pmdarima: None
statsforecast: 1.6.0
      tsfresh: None
      tslearn: None
        torch: None
   tensorflow: None
tensorflow_probability: None
</details>

<!-- Thanks for contributing! -->



Discussion:

Resolving patch:
diff --git a/sktime/forecasting/base/adapters/_generalised_statsforecast.py b/sktime/forecasting/base/adapters/_generalised_statsforecast.py
--- a/sktime/forecasting/base/adapters/_generalised_statsforecast.py
+++ b/sktime/forecasting/base/adapters/_generalised_statsforecast.py
@@ -504,7 +504,7 @@ def predict(self, h, X=None, level=None):
             self.prediction_intervals = ConformalIntervals(h=h)
 
         level = sorted(level)
-        coverage = [round(1 - (_l / 100), 2) for _l in level]
+        coverage = [round(_l / 100, 2) for _l in level]
 
         pred_int = self.estimator.predict_interval(
             fh=range(1, h + 1), X=X, coverage=coverage
@@ -532,7 +532,7 @@ def predict_in_sample(self, level=None):
             return {"fitted": fitted}
 
         level = sorted(level)
-        coverage = [round(1 - (_l / 100), 2) for _l in level]
+        coverage = [round(_l / 100, 2) for _l in level]
         pred_int = self.estimator.predict_interval(
             fh=self.estimator._y.index, X=self.estimator._X, coverage=coverage
         )


Test patch:
diff --git a/sktime/forecasting/tests/test_statsforecast.py b/sktime/forecasting/tests/test_statsforecast.py
new file mode 100644
--- /dev/null
+++ b/sktime/forecasting/tests/test_statsforecast.py
@@ -0,0 +1,43 @@
+"""Tests for StatsForecast.
+
+# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)
+"""
+
+from unittest.mock import patch
+
+import numpy as np
+import pandas as pd
+import pytest
+
+from sktime.forecasting.base import ForecastingHorizon
+from sktime.forecasting.statsforecast import StatsForecastMSTL
+from sktime.tests.test_switch import run_test_for_class
+
+
+@pytest.mark.skipif(
+    not run_test_for_class(StatsForecastMSTL),
+    reason="run test only if softdeps are present and incrementally (if requested)",
+)
+@patch("statsforecast.models.AutoETS", autospec=True)
+def test_statsforecast_mstl(mock_autoets):
+    """
+    Check that StatsForecast MSTL adapter calls trend forecaster with
+    the correct arguments.
+    """
+    from sktime.datasets import load_airline
+
+    y = load_airline()
+
+    predict = mock_autoets.return_value.predict
+    predict.return_value = {
+        "mean": np.arange(36, dtype=np.float64),
+        "lo-95.0": np.arange(36, dtype=np.float64),
+        "hi-95.0": np.arange(36, dtype=np.float64),
+    }
+
+    model = StatsForecastMSTL(season_length=[12])
+    model.fit(y)
+    fh_index = pd.PeriodIndex(pd.date_range("1961-01", periods=36, freq="M"))
+    fh = ForecastingHorizon(fh_index, is_relative=False)
+    model.predict_interval(fh, coverage=0.95)
+    predict.assert_called_with(36, X=None, level=[95.0])