@@ -19,9 +19,10 @@ def get_params(data, denominator_col, numerator_cols, date_col, scales, logger):
19
19
series column in the data.
20
20
"""
21
21
tmp = data .reset_index ()
22
- denoms = tmp .groupby (date_col ).sum ()[denominator_col ]
23
- nums = tmp .groupby (date_col ).sum ()[numerator_cols ]
24
-
22
+ denoms = tmp .groupby (date_col ).sum (numeric_only = True )[denominator_col ]
23
+ nums = tmp .groupby (date_col ).sum (numeric_only = True )[numerator_cols ]
24
+ if nums .shape [0 ] < 7 :
25
+ logger .warning ("Trying to handle weekday effects with fewer than 7 days worth of data. This will probably not work." )
25
26
# Construct design matrix to have weekday indicator columns and then day
26
27
# indicators.
27
28
X = np .zeros ((nums .shape [0 ], 6 + nums .shape [0 ]))
@@ -40,7 +41,9 @@ def get_params(data, denominator_col, numerator_cols, date_col, scales, logger):
40
41
logger .error ("Unable to calculate weekday correction" )
41
42
else :
42
43
params [i ,:] = result
43
-
44
+ if np .exp (- params ).max () == np .inf :
45
+ logger .warning ("largest weekday correction is infinite. Defaulting to no correction" )
46
+ params = np .zeros ((nums .shape [1 ], X .shape [1 ]))
44
47
return params
45
48
46
49
@staticmethod
@@ -93,11 +96,12 @@ def _fit(X, scales, npnums, npdenoms):
93
96
for scale in scales :
94
97
try :
95
98
prob = cp .Problem (cp .Minimize ((- ll + lmbda * penalty ) / scale ))
96
- _ = prob .solve ()
99
+ _ = prob .solve (solver = cp . ECOS )
97
100
return b .value
98
101
except SolverError :
99
102
# If the magnitude of the objective function is too large, an error is
100
103
# thrown; Rescale the objective function by going through loop
104
+ print (f"Solver didn't work at { scale } x" )
101
105
continue
102
106
return None
103
107
0 commit comments