Skip to content

Commit aa3ccc5

Browse files
committed
replace print statements with logging msgs for model fit funcs
1 parent e8e718f commit aa3ccc5

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

pyhctsa/operations/model_fit.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from statsmodels.stats.diagnostic import acorr_ljungbox
1010
from statsmodels.tsa.ar_model import AutoReg, ar_select_order
1111
from lmfit.models import SineModel
12+
import logging
1213

1314
from ..operations.correlation import autocorr, first_crossing
1415
from ..operations.stationarity import sliding_window
@@ -319,7 +320,7 @@ def local_simple(y: ArrayLike, forecast_meth: str = 'mean',
319320
lp = train_length
320321
evalr = np.arange(lp, N) #range over which to evaluate the forecast
321322
if np.size(evalr) == 0:
322-
print("This time series is too short for forecasting")
323+
logging.warning("This time series is too short for forecasting")
323324
return np.nan
324325
res = np.zeros(len(evalr))
325326
if forecast_meth == 'mean':
@@ -400,15 +401,15 @@ def exp_smoothing(x: ArrayLike, n_train: Union[None, int, float] = None,
400401
min_train, max_train = 100, 1000
401402

402403
if n_train > max_train:
403-
print(f"Training set size reduced from {n_train} to {max_train}.")
404+
logging.info(f"Training set size reduced from {n_train} to {max_train}.")
404405
n_train = max_train
405406

406407
if n_train < min_train:
407-
print(f"Training set size increased from {n_train} to {min_train}.")
408+
logging.info(f"Training set size increased from {n_train} to {min_train}.")
408409
n_train = min_train
409410

410411
if N < n_train:
411-
print("Time series is too short for the specified training size.")
412+
logging.warning("Time series is too short for the specified training size.")
412413
return np.nan
413414

414415
# --- Find Optimal Alpha ---
@@ -427,7 +428,7 @@ def exp_smoothing(x: ArrayLike, n_train: Union[None, int, float] = None,
427428
# Check for valid RMSEs before fitting
428429
valid_indices = ~np.isnan(rmses)
429430
if np.sum(valid_indices) < 3:
430-
print("Not enough valid points for quadratic fit; choosing best alpha from search.")
431+
logging.info("Not enough valid points for quadratic fit; choosing best alpha from search.")
431432
alphamin = alphar[np.nanargmin(rmses)] if np.any(valid_indices) else 0.5
432433
else:
433434
# Fit quadratic to the 3 points with the lowest RMSE
@@ -463,7 +464,7 @@ def exp_smoothing(x: ArrayLike, n_train: Union[None, int, float] = None,
463464

464465
valid_ref = ~np.isnan(rmses_ref)
465466
if not np.any(valid_ref):
466-
print("Could not compute RMSE in refined search; using previous alpha.")
467+
logging.info("Could not compute RMSE in refined search; using previous alpha.")
467468
else:
468469
p2 = np.polyfit(alphar_ref[valid_ref], rmses_ref[valid_ref], 2)
469470
if p2[0] < 0: # Bad fit, fallback to best alpha in search
@@ -482,7 +483,7 @@ def exp_smoothing(x: ArrayLike, n_train: Union[None, int, float] = None,
482483
yp, xp = y_fit[2:], x[2:]
483484

484485
if len(yp) < 2:
485-
print("Not enough points to calculate residual statistics.")
486+
logging.warning("Not enough points to calculate residual statistics.")
486487
residout = {'mean': np.nan, 'std': np.nan, 'AC1': np.nan}
487488
else:
488489
residuals = yp - xp

0 commit comments

Comments
 (0)