Lag plots

A lag plot is a scatter plot for a time series and the same data lagged. With such a plot, we can check whether there is a possible correlation between CPU transistor counts this year and the previous year, for instance. The lag_plot() pandas function in pandas.tools.plotting can draw a lag plot. Draw a lag plot with the default lag of 1 for the CPU transistor counts, as follows:

lag_plot(np.log(df['trans_count']))

Refer to the following plot for the end result:

Lag plots

The following code for the lag plot example can also be found in the lag_plot.py file in this book's code bundle:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pandas.tools.plotting import lag_plot


df = pd.read_csv('transcount.csv')
df = df.groupby('year').aggregate(np.mean)

gpu = pd.read_csv('gpu_transcount.csv')
gpu = gpu.groupby('year').aggregate(np.mean)

df = pd.merge(df, gpu, how='outer', left_index=True, right_index=True)
df = df.replace(np.nan, 0)
lag_plot(np.log(df['trans_count']))
plt.show()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.197.10