Search code examples
pythonpandaspicklefacebook-prophet

why does pickle file of fbprophet model need so much memory on hard drive?


I created a simple fbprophet model with the airpassengers data:

I created a simple fbprophet model with the airpassengers data:

import pandas as pd
import pickle
from fbprophet import Prophet
import sys

df = pd.read_csv("airline-passengers.csv")

# preprocess columns as fbprophet expects it
df.rename(columns={"Month": "ds", "Passengers": "y"}, inplace=True)
df["ds"] = pd.to_datetime(df["ds"])

m = Prophet()
m.fit(df)

However, when I save the object m:

with open("p_model", "wb") as f:
    pickle.dump(m, f)

it needs >1 MB of memory on my hard drive. The object m itself seems to be rather small, as sys.getsizeof(m) returns 56.

Why is the pickle file so large? Is there a suitable alternative for saving the the object for later reuse? Thanks in advance.


Solution

  • Thanks to the link of @Kohelet, I found the solultion, it was the stan_backend attribute:

    m.stan_backend = None
    

    This reduced the filesize on hard drive to around 18 KB.

    Im am still wondering why this is not visible when invoking sys.sizeof(m)