Closed rosalinesway closed 2 years ago
@rosalinesway
from kats.models.prophet import ProphetModel, ProphetParams
from fbprophet.serialize import model_to_json
m = ProphetModel(TimeSeriesData(df), ProphetParams(seasonality_mode='multiplicative'))
m.fit()
with open('serialized_model.json', 'w') as file:
file.write(model_to_json(m.model))
@neelabalan I ran the same command as you showed, and the same error occurred AttributeError: 'ProphetModel' object has no attribute 'history'
@rosalinesway
ok, I think what breaks is using the ProphetModel
from the result of the backtester.
ALL_ERRORS = ["mape", "smape", "mae", "mase", "mse", "rmse"]
backtester_prophet = CrossValidation(
error_methods=ALL_ERRORS,
data=DATA_TS,
params=params,
train_percentage=50,
test_percentage=20,
model_class=ProphetModel,
num_folds=10,
)
backtester_prophet.run_cv()
backtester_errors["prophet"] = {}
for error, value in backtester_prophet.errors.items():
backtester_errors["prophet"][error] = value
# results: List of tuples
# (training_data, testing_data, trained_model, forecast_predictions)
(
train_data,
test_data,
trained_model,
forecast_predictions,
) = backtester_prophet.results[0]
did you use trained_model.model
? The difference is
type(trained_model)
# kats.models.prophet.ProphetModel
type(trained_model.model)
# fbprophet.forecaster.Prophet
The above backtester example works fine for me
from kats.utils import backtesters
ALL_ERRORS = ["mape", "smape", "mae", "mase", "mse", "rmse"]
backtester_prophet = backtesters.CrossValidation(
error_methods=ALL_ERRORS,
data=tsd,
params=ProphetParams(seasonality_mode='multiplicative'),
train_percentage=50,
test_percentage=20,
model_class=ProphetModel,
num_folds=10,
)
backtester_prophet.run_cv()
(
train_data,
test_data,
trained_model,
forecast_predictions,
) = backtester_prophet.results[0]
with open('serialized_model.json', 'w') as file:
file.write(model_to_json(trained_model.model))
@neelabalan that did work, thanks!
Hi,
I tried using the kats package with the default prophet functions to serialize the prophet model using the below code:
Currently, it is throwing this error: