Created
July 29, 2022 16:04
-
-
Save erikbern/6af5c10083daeae77c8735d9fd0765f1 to your computer and use it in GitHub Desktop.
Run Prophet inside Modal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import modal | |
stub = modal.Stub(image=modal.DebianSlim().pip_install(["prophet"])) | |
@stub.function | |
def run(): | |
import pandas as pd | |
from prophet import Prophet | |
from matplotlib import pyplot | |
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv') | |
df.head() | |
m = Prophet() | |
m.fit(df) | |
future = m.make_future_dataframe(periods=365) | |
future.tail() | |
forecast = m.predict(future) | |
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail() | |
fig1 = m.plot(forecast) | |
buf = io.BytesIO() | |
pyplot.savefig(buf) | |
return buf.getvalue() | |
if __name__ == "__main__": | |
with stub.run(): | |
data = run() | |
with open("prophet.png", "wb") as f: | |
f.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment