社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Rick

Rick 最近创建的主题
Rick 最近回复了

我对这个库不是很有经验,但它似乎需要一个系列而不是一个数据列表。导入pandas.pd并将数据转换为pd.Series:

import matplotlib.pyplot as plt
from statsmodels.tsa.holtwinters import ExponentialSmoothing, SimpleExpSmoothing, Holt
import pandas as pd

data = [253993,275396.2,315229.5,356949.6,400158.2,442431.7,495102.9,570164.8,\
640993.1,704250.4,767455.4,781807.8,776332.3,794161.7,834177.7,931651.5,\
1028390,1114914]

series = pd.Series(data)

# Holt's Method
fit1 = Holt(series).fit(smoothing_level=0.8, smoothing_slope=0.2, optimized=False)
l1, = plt.plot(list(fit1.fittedvalues) + list(fit1.forecast(5)), marker='o')

fit2 = Holt(series, exponential=True).fit(smoothing_level=0.8, smoothing_slope=0.2, optimized=False)
l2, = plt.plot(list(fit2.fittedvalues) + list(fit2.forecast(5)), marker='o')

fit3 = Holt(series, damped=True).fit(smoothing_level=0.8, smoothing_slope=0.2)
l3, = plt.plot(list(fit3.fittedvalues) + list(fit3.forecast(5)), marker='o')

l4, = plt.plot(series, marker='o')
plt.legend(handles = [l1, l2, l3, l4], labels = ["Holt's linear trend", "Exponential trend", "Additive damped trend", 'data'], loc = 'best', prop={'size': 7})
plt.show()
6 年前
回复了 Rick 创建的主题 » 修改python字典的值

在不过度修改代码的情况下,我的建议是:

my_dicts =  {'key1': 'true', 'key2': 'true'}

for key in my_dicts:
    if my_dicts[key] == 'true': my_dicts[key] = 'True'

print("After:")
for key, value in my_dicts.iteritems():
    print(key + " = " + my_dicts[key])