skforecast icon indicating copy to clipboard operation
skforecast copied to clipboard

consider improve the efficiency maybe?

Open Bennett561 opened this issue 1 year ago • 1 comments

The functionality of the package is mostly satisfying, but with all due respect, when i compare the performance of skforecast with the model i develop by myself, i found it much slower to use the framework. Once i dive deep into the source code, it comes out that the efficiency problem needs some focus. For example, the _create_lags function may be improved as:

def _create_lags(self, y: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
    n_splits = len(y) - self.max_lag
    if n_splits <= 0:
        raise Exception(
            "max lag must be less than the length of the series."
        )
    X_data = np.full(shape=(n_splits, len(self.lags)), fill_value=np.nan, dtype=float)

    i = 0
    for lag in self.lags:
        X_data[:, i] = y[self.max_lag - lag: -lag]
        i += 1

    y_data = y[self.max_lag:]
    return X_data, y_data

And i'm sure there is a lot to do about performance optimization, expecting a brand-new version with both satisfying features and speed!

Bennett561 avatar Aug 03 '22 09:08 Bennett561

Hi @Bennett561 thanks a lot for the suggestion. Yes, there are many potential optimizations. Could you give some more details about the benchmark you have done? Length of the serie, number of lags, regressor used and time required for training.

Thanks

JoaquinAmatRodrigo avatar Aug 03 '22 15:08 JoaquinAmatRodrigo

Hi @Bennett561, we have refactored _create_lags_ in ForecasterAutoreg and ForecasterAutoregMultiSeries with your input. We have mentioned you in the changelog. Thank you!

JavierEscobarOrtiz avatar Oct 26 '22 07:10 JavierEscobarOrtiz