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

Method set_changepoints

python/prophet/forecaster.py:408–455  ·  view source on GitHub ↗

Set changepoints Sets m$changepoints to the dates of changepoints. Either: 1) The changepoints were passed in explicitly. A) They are empty. B) They are not empty, and need validation. 2) We are generating a grid of them. 3) The user prefers n

(self)

Source from the content-addressed store, hash-verified

406 self.extra_regressors[name]['std'] = std
407
408 def set_changepoints(self):
409 """Set changepoints
410
411 Sets m$changepoints to the dates of changepoints. Either:
412 1) The changepoints were passed in explicitly.
413 A) They are empty.
414 B) They are not empty, and need validation.
415 2) We are generating a grid of them.
416 3) The user prefers no changepoints be used.
417 """
418 if self.changepoints is not None:
419 if len(self.changepoints) == 0:
420 pass
421 else:
422 too_low = min(self.changepoints) < self.history['ds'].min()
423 too_high = max(self.changepoints) > self.history['ds'].max()
424 if too_low or too_high:
425 raise ValueError(
426 'Changepoints must fall within training data.')
427 else:
428 # Place potential changepoints evenly through first
429 # `changepoint_range` proportion of the history
430 hist_size = int(np.floor(self.history.shape[0]
431 * self.changepoint_range))
432 if self.n_changepoints + 1 > hist_size:
433 self.n_changepoints = hist_size - 1
434 logger.info(
435 'n_changepoints greater than number of observations. '
436 'Using {n_changepoints}.'
437 .format(n_changepoints=self.n_changepoints)
438 )
439 if self.n_changepoints > 0:
440 cp_indexes = (
441 np.linspace(0, hist_size - 1, self.n_changepoints + 1)
442 .round()
443 .astype(int)
444 )
445 self.changepoints = (
446 self.history.iloc[cp_indexes]['ds'].tail(-1)
447 )
448 else:
449 # set empty changepoints
450 self.changepoints = pd.Series(pd.to_datetime([]), name='ds')
451 if len(self.changepoints) > 0:
452 self.changepoints_t = np.sort(np.array(
453 (self.changepoints - self.start) / self.t_scale))
454 else:
455 self.changepoints_t = np.array([0]) # dummy changepoint
456
457 @staticmethod
458 def fourier_series(

Callers 5

preprocessMethod · 0.95
test_get_changepointsMethod · 0.95

Calls

no outgoing calls