是否有庞大版本的熊猫自相关绘图方法?

Ayb*_*vuz 3 python machine-learning time-series pandas bokeh

假设我们有一个称为"系列"的时间序列对象.我知道它非常容易使用autocorrelation_plot()方法来绘制系列对象的Lag和Autocorrelation维度.

这是代码:

from matplotlib import pyplot
from pandas.tools.plotting import autocorrelation_plot
autocorrelation_plot(series)
pyplot.show()
Run Code Online (Sandbox Code Playgroud)

这是大熊猫的情节:

在此输入图像描述

有没有办法使用散景服务器获得相同的情节?

Ayb*_*vuz 6

就在这里.我编写的代码可以提供与pandas autocorrelation_plot()方法相同的结果.

这是代码:

from bokeh.layouts import column
from bokeh.plotting import figure, curdoc
import timeseries_model_creator  # to get data
import numpy as np

TimeSeriesModelCreator = timeseries_model_creator.TimeSeriesModelCreator()
series = TimeSeriesModelCreator.read_csv()  # time series object

def get_autocorrelation_plot_params(series):
    n = len(series)
    data = np.asarray(series)

    mean = np.mean(data)
    c0 = np.sum((data - mean) ** 2) / float(n)

    def r(h):
        return ((data[:n - h] - mean) *
                (data[h:] - mean)).sum() / float(n) / c0
    x = np.arange(n) + 1
    y = map(r, x)
    print "x : ", x, " y : ", y
    z95 = 1.959963984540054
    z99 = 2.5758293035489004
    return n, x, y, z95, z99

n, x, y, z95, z99 = get_autocorrelation_plot_params(series)

auto_correlation_plot2 = figure(title='Time Series Auto-Correlation', plot_width=1000,
                                plot_height=500, x_axis_label="Lag", y_axis_label="Autocorrelation")

auto_correlation_plot2.line(x, y=z99 / np.sqrt(n), line_dash='dashed', line_color='grey')
auto_correlation_plot2.line(x, y=z95 / np.sqrt(n), line_color='grey')
auto_correlation_plot2.line(x, y=0.0, line_color='black')
auto_correlation_plot2.line(x, y=-z95 / np.sqrt(n), line_color='grey')
auto_correlation_plot2.line(x, y=-z99 / np.sqrt(n), line_dash='dashed', line_color='grey')

auto_correlation_plot2.line(x, y, line_width=2)
auto_correlation_plot2.circle(x, y, fill_color="white", size=8)  # optional

curdoc().add_root(column(auto_correlation_plot2))
Run Code Online (Sandbox Code Playgroud)

这是散景图:

在此输入图像描述