Prophet: save model for python

Created on 3 Nov 2018  路  6Comments  路  Source: facebook/prophet

Hi, Can I save the model after fitting? I can't find the function. How can I save a model to file? And How can I load the saved model when I want to predict by the model? Thank you

Most helpful comment

You can use pickle to save the Prophet model after fitting!

import pickle
pkl_path = "path/to/save/Prophet.pkl"
with open(pkl_path, "wb") as f:
    # Pickle the 'Prophet' model using the highest protocol available.
    pickle.dump(m, f)

# save the dataframe
forecast.to_pickle("path/to/data/forecast.pkl")
print("*** Data Saved ***")

Then to load them again

# read the Prophet model object
with open(pkl_path, 'rb') as f:
    m = pickle.load(f)

fcast = pd.read_pickle("path/to/data/forecast.pkl")

All 6 comments

You can use pickle to save the Prophet model after fitting!

import pickle
pkl_path = "path/to/save/Prophet.pkl"
with open(pkl_path, "wb") as f:
    # Pickle the 'Prophet' model using the highest protocol available.
    pickle.dump(m, f)

# save the dataframe
forecast.to_pickle("path/to/data/forecast.pkl")
print("*** Data Saved ***")

Then to load them again

# read the Prophet model object
with open(pkl_path, 'rb') as f:
    m = pickle.load(f)

fcast = pd.read_pickle("path/to/data/forecast.pkl")

You can use pickle to save the Prophet model after fitting!

import pickle
pkl_path = "path/to/save/Prophet.pkl"
with open(pkl_path, "wb") as f:
    # Pickle the 'Prophet' model using the highest protocol available.
    pickle.dump(m, f)

# save the dataframe
forecast.to_pickle("path/to/data/forecast.pkl")
print("*** Data Saved ***")

Then to load them again

# read the Prophet model object
with open(pkl_path, 'rb') as f:
    m = pickle.load(f)

fcast = pd.read_pickle("path/to/data/forecast.pkl")

Does that mean every time it can just load the new produced data and then save the model. Next time,
just load the model and fit with the new produced data again instead of query the whole time series data ?

Thank you for your reply. I can save and load model successfully. So, Can I fit angin if there is some new data after I save a fitted model ?
I want to load the model and then use the new data to get a new model, but I don't know how to do.

@summerchenjuan I think what you're asking might be related to #46. If you want to load in an old model and update to incorporate some incremental change in the data (e.g., a new day of data), then there is currently no way to do that. #46 outlines some of what needs to be done to get this working, but for now the model needs to be re-fit from scratch with the new data. Is that what you're hoping to do?

Hi, I made a Prophet model for my time series data. I was looking for a way to update my model with the new batch and I found this page.
@bletham mentioned that this feature was not available for Prophet at that time.

My question is that is it still unavailable for the prophet to load in an old model and update to incorporate some incremental change in the data?

Thanks!

@saeideh-sh there's isn't a built-into-the-package feature for this, but there is a documentation page here that describes how to do it with code examples: https://facebook.github.io/prophet/docs/additional_topics.html#updating-fitted-models

Was this page helpful?
0 / 5 - 0 ratings