Skip to content

Commit

Permalink
add random state to LinearModel SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuabmoore committed May 18, 2024
1 parent 0a53795 commit 82bb9ef
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pyspi/statistics/misc.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]))

Expand Down

0 comments on commit 82bb9ef

Please sign in to comment.