You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.9 KiB
Python

import matplotlib.pyplot as plt
import pandas as pd
from statsmodels.tsa.holtwinters import ExponentialSmoothing
import requests
import json
# ts = pd.read_csv("d:\\files\\Features count.csv")
# ts.plot()
# plt.grid()
# plt.show()
# moving_avg = ts.rolling(4).mean()
# ts.plot()
# plt.plot(moving_avg, color='green', label='Moving average')
# plt.legend()
# plt.grid()
# model = ExponentialSmoothing(ts, trend="additive", seasonal="additive", seasonal_periods=5)
# fit1 = model.fit()
# pred1 = fit1.forecast(5)
# plt.plot(ts, label='Features count')
# plt.plot(pred1, color='red', label='Holt-Winters forecast')
# plt.legend()
# plt.grid()
ts = pd.read_csv("d:\\files\\Testing time.csv")
model = ExponentialSmoothing(ts, trend="additive", seasonal="additive", seasonal_periods=7)
fit1 = model.fit()
pred1 = fit1.forecast(10)
plt.plot(ts, label='Testing time')
plt.plot(pred1, color='red', label='Holt-Winters forecast')
plt.legend()
plt.grid()
plt.show()
# Использовать внешний сервис прогнозирования
time_series = {
"originalTimeSeries": {
"values": [
{
"date": "2023-04-16T06:29:50.668476",
"value": 1
},
{
"date": "2023-04-17T06:29:50.668476",
"value": 2
},
{
"date": "2023-04-18T06:29:50.668476",
"value": 3
},
{
"date": "2023-04-19T06:29:50.668476",
"value": 4
},
{
"date": "2023-04-20T06:29:50.668476",
"value": 5
},
{
"date": "2023-04-21T06:29:50.668476",
"value": 6
},
{
"date": "2023-04-22T06:29:50.668476",
"value": 5
},
{
"date": "2023-04-23T06:29:50.668476",
"value": 4
},
{
"date": "2023-04-24T06:29:50.668476",
"value": 3
},
{
"date": "2023-04-25T06:29:50.668476",
"value": 2
},
{
"date": "2023-04-26T06:29:50.668476",
"value": 1
},
{
"date": "2023-04-27T06:29:50.668476",
"value": 2
}
],
"name": 'test'
},
"countForecast": 5
}
source = []
for v in time_series['originalTimeSeries']['values']:
source.append(v['value'])
url = "http://time-series.athene.tech/api/1.0/getForecast"
headers = {'Content-type': 'application/json'}
r = requests.post(url, data=json.dumps(time_series), headers=headers)
forecast = [item['value'] for item in r.json()['timeSeries']['values']]
plt.plot(range(1, 1+len(source)), source)
plt.plot(range(len(source), len(source)+len(forecast)), forecast)
plt.grid()
plt.show()