gpt4 book ai didi

python - 是否可以使用 Jupyter Notebook 创建 Rest API?,如果可以,如何为以下 json 格式的代码创建 Rest API

转载 作者:行者123 更新时间:2023-12-01 01:48:10 27 4
gpt4 key购买 nike

我已经建立了一个时间序列分析模型,它将预测接下来几天的航行,该模型运行良好,但我想使用 Anaconda jupyter 笔记本将其转换为 JSON 格式的 Rest API,请让我知 Prop 体方法。提前致谢。

这是代码:

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

最佳答案

“jupyter Notebook Rest api”找到了针对此问题的有希望的谷歌搜索结果,例如https://blog.ouseful.info/2017/09/06/building-a-json-api-using-jupyer-notebooks-in-under-5-minutes/

您尝试过使用kernelgateway吗?

关于python - 是否可以使用 Jupyter Notebook 创建 Rest API?,如果可以,如何为以下 json 格式的代码创建 Rest API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51018536/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com