MCPcopy
hub / github.com/facebook/prophet / initialize_scales

Method initialize_scales

python/prophet/forecaster.py:359–406  ·  view source on GitHub ↗

Initialize model scales. Sets model scaling factors using df. Parameters ---------- initialize_scales: Boolean set the scales or not. df: pd.DataFrame for setting scales.

(self, initialize_scales, df)

Source from the content-addressed store, hash-verified

357 return df
358
359 def initialize_scales(self, initialize_scales, df):
360 """Initialize model scales.
361
362 Sets model scaling factors using df.
363
364 Parameters
365 ----------
366 initialize_scales: Boolean set the scales or not.
367 df: pd.DataFrame for setting scales.
368 """
369 if not initialize_scales:
370 return
371
372 if self.growth == 'logistic' and 'floor' in df:
373 self.logistic_floor = True
374 if self.scaling == "absmax":
375 self.y_min = float((df['y'] - df['floor']).abs().min())
376 self.y_scale = float((df['y'] - df['floor']).abs().max())
377 elif self.scaling == "minmax":
378 self.y_min = df['floor'].min()
379 self.y_scale = float(df['cap'].max() - self.y_min)
380 else:
381 if self.scaling == "absmax":
382 self.y_min = 0.
383 self.y_scale = float((df['y']).abs().max())
384 elif self.scaling == "minmax":
385 self.y_min = df['y'].min()
386 self.y_scale = float(df['y'].max() - self.y_min)
387 if self.y_scale == 0:
388 self.y_scale = 1.0
389
390 self.start = df['ds'].min()
391 self.t_scale = df['ds'].max() - self.start
392 for name, props in self.extra_regressors.items():
393 standardize = props['standardize']
394 n_vals = len(df[name].unique())
395 if n_vals < 2:
396 standardize = False
397 if standardize == 'auto':
398 if set(df[name].unique()) == {1, 0}:
399 standardize = False # Don't standardize binary variables.
400 else:
401 standardize = True
402 if standardize:
403 mu = float(df[name].mean())
404 std = float(df[name].std())
405 self.extra_regressors[name]['mu'] = mu
406 self.extra_regressors[name]['std'] = std
407
408 def set_changepoints(self):
409 """Set changepoints

Callers 1

setup_dataframeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected