zoukankan      html  css  js  c++  java
  • python指数平滑预测

    1、无明显单调或周期变化的参数

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    from statsmodels.tsa.holtwinters import SimpleExpSmoothing
    
    x1 = np.linspace(0, 1, 100)
    y1 = pd.Series(np.multiply(x1, (x1 - 0.5)) + np.random.randn(100))
    ets1 = SimpleExpSmoothing(y1)
    r1 = ets1.fit()
    pred1 = r1.predict(start=len(y1), end=len(y1) + len(y1)//2)
    
    pd.DataFrame({
        'origin': y1,
        'fitted': r1.fittedvalues,
        'pred': pred1
    }).plot(legend=True)
    plt.show()

    2、单调变化的参数

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    
    from statsmodels.tsa.holtwinters import Holt
    
    x2 = np.linspace(0, 99, 100)
    y2 = pd.Series(0.1 * x2 + 2 * np.random.randn(100))
    ets2 = Holt(y2)
    r2 = ets2.fit()
    pred2 = r2.predict(start=len(y2), end=len(y2) + len(y2)//2)
    
    pd.DataFrame({
        'origin': y2,
        'fitted': r2.fittedvalues,
        'pred': pred2
    }).plot(legend=True)
    plt.show()

    3、具有周期变化的参数

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    
    from statsmodels.tsa.holtwinters import ExponentialSmoothing
    
    x3 = np.linspace(0, 4 * np.pi, 100)
    y3 = pd.Series(20 + 0.1 * np.multiply(x3, x3) + 8 * np.cos(2 * x3) + 2 * np.random.randn(100))
    ets3 = ExponentialSmoothing(y3, trend='add', seasonal='add', seasonal_periods=25)
    r3 = ets3.fit()
    pred3 = r3.predict(start=len(y3), end=len(y3) + len(y3)//2)
    
    pd.DataFrame({
        'origin': y3,
        'fitted': r3.fittedvalues,
        'pred': pred3
    }).plot(legend=True)
    plt.show()

    参考:https://www.jianshu.com/p/2c607fe926f0

  • 相关阅读:
    sqlite设置主键
    sqlite 分页
    Server.Transfer方法在页面间传值
    JS实现背景透明度可变,文字不透明的效果
    css hack 区分浏览器
    Asp.net(c#)实现多线程断点续传
    C# 中的委托和事件
    使用C#的HttpWebRequest访问网站
    相似图片搜索的原理
    asp.net内存溢出问题
  • 原文地址:https://www.cnblogs.com/judes/p/12619566.html
Copyright © 2011-2022 走看看