From 82bb9efd2b142c901e5972383f557c8776cf0dcf Mon Sep 17 00:00:00 2001 From: jmoo2880 Date: Sun, 19 May 2024 07:24:11 +1000 Subject: [PATCH] add random state to LinearModel SPI --- pyspi/statistics/misc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyspi/statistics/misc.py b/pyspi/statistics/misc.py index 708a47d..b7a23e3 100644 --- a/pyspi/statistics/misc.py +++ b/pyspi/statistics/misc.py @@ -1,5 +1,6 @@ import warnings import numpy as np +import inspect from statsmodels.tsa import stattools from statsmodels.tsa.vector_ar.vecm import coint_johansen @@ -114,8 +115,12 @@ def __init__(self, model): def bivariate(self, data, i=None, j=None): z = data.to_numpy() with warnings.catch_warnings(): - warnings.simplefilter("ignore") - mdl = self._model().fit(z[i], np.ravel(z[j])) + warnings.simplefilter("ignore") + model_params = inspect.signature(self._model).parameters + if "random_state" in model_params: + mdl = self._model(random_state=42).fit(z[i], np.ravel(z[j])) + else: + mdl = self._model().fit(z[i], np.ravel(z[j])) y_predict = mdl.predict(z[i]) return mean_squared_error(y_predict, np.ravel(z[j]))