統計検定に
python で
結果を
入力データ、 実施内容に ついて
入力データ
Google Search Console のデータを 使用し、 16月間の 表示数 の 変遷の 相関を 評価します。 実施内容
- 時系列データの
日次での コレログラムを 描画する。 - 時系列データの
月次での コレログラムを 描画する。
- 時系列データの
時系列データの 日次での コレログラムを 描画する。
Google Search Console の データを 取得。
ライブラリ searchconsole を
import pandas as pd import searchconsole # サービスアカウント のキーを指定して、認証する account = searchconsole.authenticate(service_account='./client_secrets.json') # データの取得 web_property = account['https://www.monotalk.xyz/'] report = web_property.query.range('today', days=-480).dimension('date').limit(25000).get() # pandas データフレームに変換し、必要な項目のみにする df = report.to_dataframe() df = df.loc[:,['date','impressions']] # 日付文字列を日付形式に変換 df['date'] = pd.to_datetime(df['date']) df = df.set_index('date')
コレログラムを 描画する
plot_acf、
plot_acf は、
import statsmodels.api as sm import matplotlib.pyplot as plt fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, figsize=(14,12)) sm.graphics.tsa.plot_acf(df['impressions'], lags=21, ax=ax1) sm.graphics.tsa.plot_pacf(df['impressions'], lags=21, ax=ax2)
グラフから わかる こと
あたり前な気が
* 前日の
* 増加傾向に
* 7日で
時系列データの 月次での コレログラムを 描画する。
Google Search Console の データを 取得。 Index を 付与。
日付ごとの
import pandas as pd import searchconsole # サービスアカウント のキーを指定して、認証する account = searchconsole.authenticate(service_account='./client_secrets.json') # データの取得 web_property = account['https://www.monotalk.xyz/'] report = web_property.query.range('today', days=-480).dimension('date').limit(25000).get() # pandas データフレームに変換し、必要な項目のみにする df = report.to_dataframe() df = df.loc[:,['date','impressions']] # 日付文字列を日付形式に変換 df['date'] = pd.to_datetime(df['date']) df = df.set_index('date') # 月と、年をindex に付与、集計する df2 = df.set_index([df.index.year, df.index.month, df.index]) df2.index.names = [ 'year', 'month', 'date'] df2 = df2.sum(level=['year', 'month']) df2 = df2.query('not(year >= 2018 and month >= 8)') # 時系列のグラフ描画 %matplotlib inline df2.plot() df2
impressions | ||
---|---|---|
year | month | |
2017 | 4 | 18983.0 |
5 | 46722.0 | |
6 | 46320.0 | |
7 | 52608.0 | |
8 | 62658.0 | |
9 | 80690.0 | |
10 | 93186.0 | |
11 | 97685.0 | |
12 | 94242.0 | |
2018 | 1 | 107181.0 |
2 | 107336.0 | |
3 | 171040.0 | |
4 | 219303.0 | |
5 | 254596.0 | |
6 | 262584.0 | |
7 | 271160.0 |
%matplotlib osx import statsmodels.api as sm import matplotlib.pyplot as plt fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, figsize=(14,12)) sm.graphics.tsa.plot_acf(df2['impressions'], lags=8, ax=ax1) sm.graphics.tsa.plot_pacf(df2['impressions'], lags=8, ax=ax2)
グラフから わかる こと
前月の
正直、
ラグ数が
参考
実施時に、
- 時系列解析_理論編 | Logics of Blue
- サイトの
PV数を ARMAモデルで 推定してみる – JBClub - SARIMAで
時系列データの 分析(PV数の 予測) - kumilog.net - 偏自己相関関数(PACF)を
解釈する - Minitab
以上です。
コメント