Mini Project)ショッピングモール受注データによるデータ分析−(4)データに基づく意思決定−プッシュ通知時間


4.データに基づく決定-プッシュ通知時間


1.ライブラリインポートと棒グラフ描画機能の定義

import numpy as np
import pandas as pd
# seaborn
import seaborn as sns
COLORS = sns.color_palette()

%matplotlib inline
def plot_bar(df, xlabel, ylabel, title, figsize=(20, 10), color=COLORS[-1], rotation=45):
    plot = df.plot(kind='bar', color=color, figsize=figsize)
    plot.set_xlabel(xlabel, fontsize=10)
    plot.set_ylabel(ylabel, fontsize=10)
    plot.set_title(title, fontsize=12)
    plot.set_xticklabels(labels=df.index, rotation=rotation)
データをロードし、InvoiceDateを再フォーマットします.
dtypes = {
    'UnitPrice': np.float32,
    'CustomerID': np.int32,
    'Quantity': np.int32
}
retail = pd.read_csv('../Data/OnlineRetailClean.csv', dtype=dtypes)
retail['InvoiceDate'] = pd.to_datetime(retail['InvoiceDate'], infer_datetime_format=True)
retail.head()
日付のフォーマットに関連する正式なライブラリリンク
書式設定前

書式設定後

2.クーポン発行等のプッシュタイミングを考える


現実的に最も注文が多い場合にプッシュするのが最も直感的な判断といえる.
主に時間(時間,分)に関わるため,InvoiceDateが最も重要な特徴といえる.
# 시간 그룹 별 고객 수를 카운트한다.
order_by_hour = retail.set_index('InvoiceDate').groupby(lambda date: date.hour).count()['CustomerID']
order_by_hour
グラフィックの描画
plot_bar(order_by_hour, 'Hour', '# Orders', 'Order by Hour')

12時代の売上高は圧倒的に高かった.
各購入イベントの時間を30分短縮する関数を定義します.
def half_an_hour(date):
    minute = ':00'
    if date.minute > 30:
        minute = ':30'
    hour = str(date.hour)
    if date.hour < 10:
        hour = '0' + hour
    return hour + minute
30分ごとの顧客数の結果
order_by_hour_half = retail.set_index('InvoiceDate').groupby(half_an_hour).count()['CustomerID']
order_by_hour_half
plot_bar(order_by_hour_half,'Half an hour', '# Orders', 'Order by half an hour')

30分単位でカットした結果、12時と12時30分、つまり12時と13時に購入したお客様が一番多かったです.
order_by_hour_half / order_by_hour_half.sum() * 100

全体の割合で見ると、12時代が全体の18%を占め、1時代が16%前後を占めている.

個人差押え通知時間を考える

  • の最近のトレンドは、アマゾンを先頭に、ユーザーに基づいてソリューションをカスタマイズすることです.
  • ユーザーごとに消費パターンが異なる場合がありますので、購入が最も多い時間帯を探してPushを送信します.
  • order_count_by_hour = retail.set_index('InvoiceDate').groupby(['CustomerID', lambda date: date.hour]).count()['StockCode']
    order_count_by_hour

    お客様の購入時間帯と購入品の購入回数によって.
    ユーザーあたりの最大注文時間の計算
    idx = order_count_by_hour.groupby('CustomerID').idxmax()

    時間別索引
    # 시간으로 indexing
    result = order_count_by_hour.loc[idx]
    result

    最終的に1時間あたりの購入者IDリストを取得
    result.reset_index().groupby('level_1').groups

    これにより、各時間帯の顧客リストの顧客にクーポンなどを送ることで、顧客の購入を引き付けることができるかもしれません.
    第4話終了