我已经为时间序列分析建立了一个模型,它将预测未来几天的航行,该模型运行良好,但我想使用anaconda jupyter笔记本将其转换为json格式的rest api,请让我知道方法。提前谢谢。
代码如下:
from pandas import Series
from statsmodels.tsa.arima_model import ARIMA
import numpy
# create a differenced series
def difference(dataset, interval=1):
diff = list()
for i in range(interval, len(dataset)):
value = dataset[i] - dataset[i - interval]
diff.append(value)
return numpy.array(diff)
# invert differenced value
def inverse_difference(history, yhat, interval=1):
return yhat + history[-interval]
# load dataset
series = Series.from_csv('mkr.csv', header=None)
# seasonal difference
X = series.values
X = X.astype('float32')
days_in_year = 365
differenced = difference(X, days_in_year)
# fit model
model = ARIMA(differenced, order=(0,0,1))
model_fit = model.fit(disp=0)
# multi-step out-of-sample forecast
forecast = model_fit.forecast(steps=7)[0]
# invert the differenced forecast to something usable
history = [x for x in X]
day = 1
for yhat in forecast:
inverted = inverse_difference(history, yhat,days_in_year)
print('Day %d sail:= %.3f' % (month, inverted))
history.append(inverted)
day += 1
1条答案
按热度按时间twh00eeo1#
“jupyter笔记本restapi”在google上搜索到的这个问题很有希望。https://blog.ouseful.info/2017/09/06/building-a-json-api-using-jupyer-notebooks-in-under-5-minutes/
你试过使用kernelgateway吗?