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

Method test_full_serialize

python/prophet/tests/test_serialize.py:60–130  ·  view source on GitHub ↗
(self, daily_univariate_ts, backend)

Source from the content-addressed store, hash-verified

58 assert np.array_equal(fcst["yhat"].values, fcst2["yhat"].values)
59
60 def test_full_serialize(self, daily_univariate_ts, backend):
61 # Construct a model with all attributes
62 holidays = pd.DataFrame(
63 {
64 "ds": pd.to_datetime(["2012-06-06", "2013-06-06"]),
65 "holiday": ["seans-bday"] * 2,
66 "lower_window": [0] * 2,
67 "upper_window": [1] * 2,
68 }
69 )
70 # Test with holidays and country_holidays
71 m = Prophet(
72 holidays=holidays,
73 seasonality_mode="multiplicative",
74 changepoints=["2012-07-01", "2012-10-01", "2013-01-01"],
75 stan_backend=backend,
76 )
77 m.add_country_holidays(country_name="US")
78 m.add_seasonality(
79 name="conditional_weekly",
80 period=7,
81 fourier_order=3,
82 prior_scale=2.0,
83 condition_name="is_conditional_week",
84 )
85 m.add_seasonality(name="normal_monthly", period=30.5, fourier_order=5, prior_scale=2.0)
86 df = daily_univariate_ts.copy()
87 df["is_conditional_week"] = [0] * 255 + [1] * 255
88 m.add_regressor("binary_feature", prior_scale=0.2)
89 m.add_regressor("numeric_feature", prior_scale=0.5)
90 m.add_regressor("numeric_feature2", prior_scale=0.5, mode="multiplicative")
91 m.add_regressor("binary_feature2", standardize=True)
92 df["binary_feature"] = ["0"] * 255 + ["1"] * 255
93 df["numeric_feature"] = range(510)
94 df["numeric_feature2"] = range(510)
95 df["binary_feature2"] = [1] * 100 + [0] * 410
96
97 train = df.head(400)
98 test = df.tail(100)
99
100 m.fit(train)
101 fcst = m.predict(test)
102 # Serialize!
103 m2 = model_from_json(model_to_json(m))
104
105 # Check that m and m2 are equal
106 assert m.__dict__.keys() == m2.__dict__.keys()
107 for k, v in m.__dict__.items():
108 if k in ["stan_fit", "stan_backend"]:
109 continue
110 if k == "params":
111 assert v.keys() == m2.params.keys()
112 for kk, vv in v.items():
113 assert np.array_equal(vv, m2.params[kk])
114 elif k in PD_SERIES and v is not None:
115 assert v.equals(m2.__dict__[k])
116 elif k in PD_DATAFRAME and v is not None:
117 # check_dtype=False since .fit() and .predict() will cooerce to the correct types

Callers

nothing calls this directly

Calls 8

add_country_holidaysMethod · 0.95
add_seasonalityMethod · 0.95
add_regressorMethod · 0.95
fitMethod · 0.95
predictMethod · 0.95
ProphetClass · 0.90
model_from_jsonFunction · 0.90
model_to_jsonFunction · 0.90

Tested by

no test coverage detected