99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀吃貨的自我修養(yǎng) | 口味蝦哪家最好吃?我用python告訴你
吃貨的自我修養(yǎng) | 口味蝦哪家最好吃?我用python告訴你
2020-07-14
收藏

CDA數(shù)據(jù)分析師 出品

作者:Mika、真達

數(shù)據(jù):真達

后期:澤龍

【導(dǎo)讀】今天我們用數(shù)據(jù)來聊一聊口味蝦。

Show me data,用數(shù)據(jù)說話

今天我們聊一聊 口味蝦

說起湖南這個地方,大家想到的肯定是各種吃的,最常聽到的就是臭豆腐,外焦里嫩,聞起來臭吃起來香,一口下去讓人回味無窮。

還有香甜軟糯的糖油粑粑,炸至金黃的糯米,外面裹著糖漿。

還有就是口味蝦了,口味蝦又叫麻辣小龍蝦。在夏天的時候,邀上三五好友,來上幾盤口味蝦,搭配上啤酒,肥宅的生活就這么快樂的開始了,味道麻辣爽口,一口下去就想吃下一口!在湖南,沒有吃上口味蝦的夏天都是不完整的。

那么湖南的吃貨們都喜歡吃哪家的口味蝦呢?今天我們就用數(shù)據(jù)來盤一盤。

我們使用Python獲取了大眾點評上長沙口味蝦店鋪的相關(guān)信息,進行了數(shù)據(jù)分析,整體流程如下:

網(wǎng)絡(luò)數(shù)據(jù)獲取

數(shù)據(jù)讀入

數(shù)據(jù)探索與可視化

K-means聚類分析

01數(shù)據(jù)讀入

首先導(dǎo)入所需包,并讀入獲取的數(shù)據(jù)集。

# 導(dǎo)入包

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

import seaborn as sns

import jieba

from pyecharts.charts import Bar, Pie, Page

from pyecharts import options as opts

from pyecharts.globals import SymbolType, WarningType

WarningType.ShowWarning = False

import plotly.express as px

import plotly.graph_objects as go

此數(shù)據(jù)集包含50個搜索頁面共745條數(shù)據(jù),字段包含:餐廳名、星級、星級評分、評論數(shù)、人均消費、推薦菜、口味、環(huán)境和服務(wù)得分。

數(shù)據(jù)預(yù)覽如下:

# 讀入數(shù)據(jù)

df = pd.read_excel('../data/長沙小龍蝦數(shù)據(jù).xlsx')

df.drop('detail_url', axis=1. inplace=True)

df.head()

02數(shù)據(jù)預(yù)處理

此處我們對數(shù)據(jù)進行如下處理以便后的分析工作。

title: 去除前后符號

star:提取星級

score: 提取數(shù)值,轉(zhuǎn)換為類別型

comment_list:提取口味、環(huán)境、服務(wù)得分

刪除多余的行和列

# 星級轉(zhuǎn)換

transform_star = {

20: '二星',

30: '三星',

35: '準(zhǔn)四星',

40: '四星',

45: '準(zhǔn)五星',

50: '五星'

}

# 處理title

df['title'] = df['title'].str.replace(r"\[\'|\'\]", "")

# star處理

df['star'] = df.star.str.extract(r'(\d+)')[0].astype('int')

df['star_label'] = df.star.map(transform_star)

# 處理score

df['score'] = df['score'].str.replace(r"\[\'|\'\]", "").replace("[]", np.nan)

df['score'] = df['score'].astype('float')

# 口味

df['taste'] = df.comment_list.str.split(',').str[0].str.extract(r'(\d+\.*\d+)').astype('float')

# 環(huán)境

df['environment'] = df.comment_list.str.split(',').str[1].str.extract(r'(\d+\.*\d+)').astype('float')

# 服務(wù)

df['service'] = df.comment_list.str.split(',').str[1].str.extract(r'(\d+\.*\d+)').astype('float')

# 刪除列

df.drop('comment_list', axis=1. inplace=True)

# 刪除行

df.dropna(subset=['taste'], axis=0. inplace=True)

# 刪除記錄少的

df = df[df.star!=20]

處理之后的數(shù)據(jù)如下,分析樣本為560條。

df.head()

03數(shù)據(jù)可視化

以下展示部分可視化代碼:

1不同星級店鋪數(shù)量分布

準(zhǔn)四星商戶最多,占比高達65%,超過四星以上的商戶占比18%,其中五星商戶數(shù)量最少,僅有10家。

# 產(chǎn)生數(shù)據(jù)

star_num = df.star.value_counts().sort_index(ascending=True)

x_data = star_num.index.map(transform_star).tolist()

y_data = star_num.values.tolist()

條形圖

bar1 = Bar(init_opts=opts.InitOpts(width='1350px', height='750px'))

bar1.add_xaxis(x_data)

bar1.add_yaxis('', y_data)

bar1.set_global_opts(title_opts=opts.TitleOpts(title='不同星級商戶數(shù)量分布'),

visualmap_opts=opts.VisualMapOpts(max_=365)

)

bar1.render()

2店鋪評論數(shù)分布

我們假設(shè)評論數(shù)目為店鋪的熱度,也就是它越火,消費人數(shù)越多,評論數(shù)目越多。

直方圖中可以看出,數(shù)據(jù)呈現(xiàn)比較嚴(yán)重的右偏分布,其中超過1萬評論的僅有兩家,我們挑選出來看一下,發(fā)現(xiàn)這兩家都是超級文和友,超級文和友是長沙網(wǎng)紅打卡地,國慶期間一天排16000+個號的超級網(wǎng)紅龍蝦館,難怪熱度會這么高。

直方圖

px.histogram(data_frame=df , x='review_num', color='star_label', histfunc='sum',

title='不同星級的評論數(shù)分布',

nbins=20. width=1150. height=750)

3人均價格區(qū)間分布

我們繪制了所有店鋪口味蝦人均消費價格分布的直方圖,發(fā)現(xiàn)價格分布在20~180元之間,其中人均消費大部分都在67-111元的區(qū)間內(nèi)。擴展看,人均消費和商戶的星級有關(guān)系嗎?

直方圖

px.histogram(data_frame=df , x='mean_price', color='star_label', histfunc='sum',

title='小龍蝦人均消費價格分布', nbins=20. width=1150. height=750)

4不同星級店鋪與價格等因素的關(guān)系

不同星級與價格的關(guān)系

這里繪制了星級和價格分布的小提琴圖,用來展示多組數(shù)據(jù)的分布狀態(tài)以及概率密度。從圖形可以看出,不同星級和價格之間的分布有顯著差異,表現(xiàn)為星級越高,平均消費價格越高。

# 小提琴圖

plt.figure(figsize=(15. 8))

sns.violinplot(x='star_label', y='mean_price', data=df,

order=['五星', '準(zhǔn)五星', '四星', '準(zhǔn)四星', '三星']

);

plt.title('不同星級和價格的關(guān)系', fontsize=20)

plt.show()

不同星級和其他得分項的關(guān)系

我們預(yù)想,星級評價越好,它在口味、環(huán)境和服務(wù)的得分越高,熱度也就越高,從繪制出來的箱線圖也可以驗證我們的這一假設(shè)。

那么店鋪得分與口味、環(huán)境、服務(wù)、評論數(shù)量、平均價格有關(guān)系嗎?接下來我們繪制一張多變量圖看一下。

4數(shù)值型變量關(guān)系

多變量圖用于探索數(shù)值型變量之間的關(guān)系,從多變量圖可以看出:

店鋪得分與口味、環(huán)境、服務(wù)得分呈現(xiàn)較為顯著的線性相關(guān),這也和之前的驗證一致;

店鋪得分和人均消費價格、評論數(shù)量關(guān)系不顯著;

口味、環(huán)境、服務(wù)得分之間有顯著的正相關(guān),三者存在高則同高的情況。

# 多變量圖

sns.pairplot(data=df[['score', 'review_num', 'mean_price', 'taste', 'environment', 'service', 'star_label']]

, hue='star_label')

plt.show()

數(shù)值型變量之間的相關(guān)系數(shù)

為了驗證上述可視化的結(jié)果,我們通過Python計算數(shù)值型變量之間的pearson相關(guān)系數(shù),根據(jù)經(jīng)驗,|r|>=0.8時,可視為高相關(guān)。從熱力圖中也可以得到上述結(jié)論。

# 相關(guān)系數(shù)

data_corr = df[['score', 'review_num', 'mean_price', 'taste', 'environment', 'service']].corr()

# 熱力圖

plt.figure(figsize=(15. 10))

sns.heatmap(data_corr, linewidths=0.1. cmap='tab20c_r', annot=True)

plt.title('數(shù)值型變量間相關(guān)系數(shù)', fontdict={'fontsize': 'xx-large', 'fontweight':'heavy'})

plt.xticks(fontsize=12)

plt.yticks(fontsize=12)

plt.show()

5推薦菜詞云圖

假設(shè)店鋪的推薦菜就是不同店鋪的熱門菜,我們使用jieba對推薦菜進行分詞并繪制詞云圖:

發(fā)現(xiàn)"鹵蝦"、"口味蝦"、"油爆蝦"是大家愛點的熱門菜。另外大家點口味蝦的同時也愛點"口味花甲"、"鳳爪"、"牛油"之類的串兒等菜。

6K-means聚類分析群集占比

聚類分析用于將樣本做群集劃分,同一集群內(nèi)成員的相似性要愈高愈好, 而不同集群間成員的相異性則要愈高愈好。我們使用Python進行了K-means聚類,對數(shù)值型變量:得分、評論數(shù)、平均價格、口味、環(huán)境、服務(wù)評論做群集劃分,這里取K為3.得到以上三群,其中非常推薦的數(shù)量有3家,一般推薦的459家,非常不推薦的有97家。我們看一下這三群的描述性統(tǒng)計:

K-means聚類分析分布

以上是不同群集的直方圖分布,通過群集分布圖,可以總結(jié)如下:

非常推薦:各項得分最高、評論數(shù)最多、價格最高

一般推薦:各項得分居中、評論數(shù)居中、價格居中

非常不推薦:各項得分最低、評論數(shù)最低、價格最低

由于在做聚類分析時候去除了一個評論數(shù)為30509.0的異常樣本。加上這條樣本,得到最終推薦的四家店鋪:

最后附上大眾點評上熱度值Top10的口味蝦店,看看有沒有你種草的店吧~

想要獲取完整數(shù)據(jù),可以私信或者留言哦。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }