Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predicting multiple variables at once with Facebook Prophet

I'm new to both Python and Facebook Prophet, so this may be a no-brainer, but I haven't been able to find an answer online.

I have a 7-column csv file. One column contains a datestamp ('ds') column with daily increments, and the other 6 columns ('y1', 'y2', 'y3', etc.) contain 6 variables whose values align with the datestamps.

Instead of creating six different two-column csv files and running Prophet six different times (predicting only one variable at a time), I'd like to find a way to predict all six variables at once. Here's what I'm trying:

df = pd.read.csv('example_file.csv')
cols = ['y1','y2','y3','y4','y5','y6']
results = []
for col in cols:
    subdf = df[['ds', col]].dropna()
    m = Prophet()
    m.fit(subdf)
    result = m.predict(m.make.future.dataframe(periods = 90))
    results.append(result)
df.predict = pd.concat(results, axis=1)
df.predict.to_csv('example_file.csv')

When I run it, I'm getting the following error:

ValueError: Dataframe must have columns 'ds' and 'y' with the dates and values respectively.

Any insight/help would be much appreciated. Thanks!

like image 676
Carl Avatar asked Aug 02 '18 16:08

Carl


1 Answers

Sorry I wanted to comment but I don't have sufficient reputation yet. Please rename your columns in the loop

subdf = subdf.rename(columns={'ds':'ds', col:'y'})

Prophet imposes the strict condition that the input columns be named ds (the time column) and y (the metric column).

like image 66
warwick12 Avatar answered Oct 16 '22 06:10

warwick12