目次
チップ価格のサンプルデータとは?
![seabornのtipサンプルデータのイメージ](https://smart-hint.com/wp-content/uploads/2022/01/image-148.jpg)
今回紹介する「レストランのチップ価格」のサンプルデータは、非常に分かりやすいシンプルなデータです
Pythonのグラフ可視化や機械学習の練習に活用することができます
日本には「チップ」の文化はありませんが、海外旅行などで経験があるのではないでしょうか?
このチップですが、レストラン(従業員)側からすると重要な収入源です
どの顧客が多く払ってくれるのか、いつのタイミングが良いのかなど分析することができます
事前準備
seabornからサンプルデータを取得しましょう
import pandas as pd
import seaborn as sns
df = sns.load_dataset('tips')
![df = sns.load_dataset('tips')](https://smart-hint.com/wp-content/uploads/2022/01/image-148.png)
データ内容のご紹介
本データは特定レストランにおいける、1テーブルごとのお会計(チップ)に関するデータです
![seabornのtipサンプルデータのデータ内容イメージ](https://smart-hint.com/wp-content/uploads/2022/01/image-149.png)
支払総額(total_bill)
total_billは支払い総額を示しています
単位がUSドルなのでご注意ください
後述しますがチップは支払い総額が大きく影響するので、重要な要因です
sns.histplot(data=df, x='total_bill')
![sns.histplot(data=df, x='total_bill')](https://smart-hint.com/wp-content/uploads/2022/01/image-150.png)
チップ(tip)
tipは本データの主役で、レストラン側に支払うチップです
sns.histplot(data=df, x='total_bill')
![sns.histplot(data=df, x='total_bill')](https://smart-hint.com/wp-content/uploads/2022/01/image-151.png)
欧米の文化ではレストランのチップは、支払い総額の「15~20%」と言われています
今回のデータでもどのくらいの割合なのか算出してみると、平均「16%」という結果でした
temp['percentage'] = (df['tip']) / (df['total_bill']) * 100
print(temp['percentage'].mean())
sns.histplot(data=temp, x='percentage')
![sns.histplot(data=temp, x='percentage')](https://smart-hint.com/wp-content/uploads/2022/01/image-153.png)
性別(sex)
sexは支払いを行った人の「性別」です
男性の方が若干、チップの支払いが多いことが分かります
sns.barplot(data=df, x='sex', y='tip')
![sns.barplot(data=df, x='sex', y='tip')](https://smart-hint.com/wp-content/uploads/2022/01/image-154.png)
喫煙者(smoker)
smokerはグループの中に「喫煙者」がいるかどうかを示しています
「性別」と「喫煙者」でヒートマップを作ってみます
smoker_sex = df.pivot_table(index='smoker', columns='sex', values='total_bill', aggfunc='count')
sns.heatmap(smoker_sex, annot=True, cmap='Blues')
![sns.heatmap(smoker_sex, annot=True, cmap='Blues')](https://smart-hint.com/wp-content/uploads/2022/01/image-155.png)
曜日(day)
dayは「曜日」を示しています
営業日の影響なのか、「木・金・土・日」の4日のみです
sns.barplot(data=df, x='day', y='tip')
![sns.barplot(data=df, x='day', y='tip')](https://smart-hint.com/wp-content/uploads/2022/01/image-156.png)
time(ディナーかランチ)
timeは食事を行った時間帯ですが、要は「ディナー」か「ランチ」のどちらかです
ディナーの方が支払総額やチップは高くなります
sns.barplot(data=df, x='time', y='tip')
![sns.barplot(data=df, x='time', y='tip')](https://smart-hint.com/wp-content/uploads/2022/01/image-157.png)
size(人数)
sizeはグループの人数です
1人の利用から、6人のグループの利用があります
sns.barplot(data=df, x='size', y='tip')
![sns.barplot(data=df, x='size', y='tip')](https://smart-hint.com/wp-content/uploads/2022/01/image-158.png)
まとめ
今回は「レストランのチップ価格」のサンプルデータをご紹介してきました
サンプルデータにしては項目も少なく、非常にシンプルな項目しかありません
ぜひseabornの可視化や機械学習の回帰モデルの分析に利用してみてください
![](https://smart-hint.com/wp-content/uploads/2021/10/titanic_2-520x300.jpg)
![](https://smart-hint.com/wp-content/uploads/2022/01/boston-520x300.jpg)
![お気に入り登録お願いします](https://smart-hint.com/wp-content/uploads/2021/09/お気に入り登録.png)