title

Connaître l'offre gastronomique et touristique de la ville de Lyon: un cas pratique de Data Intelligence et Machine Learning pour l'analyse des comportements sociaux avec Google Maps

A cette occasion, nous allons effectuer une étude exploratoire des données Google Maps associées à la ville de Lyon, pour cela nous utiliserons l'extraction de données dans Google Maps pour découvrir des données utiles sur les restaurants ou leurs attractions touristiques: noms, types entreprise, nombre d'étoiles, coordonnées, heures les plus fréquentées, etc.

Toutes ces données peuvent être utilisées pour obtenir beaucoup de connaissances sur l'entreprise / l'emplacement et ses environs, pour cela, nous commençons cette promenade avec quelque chose du plus typique de Lyon: sa gastronomie et ses attractions touristiques pour découvrir des Geoinsights intéressants des restaurants, améliorer la l'expérience client, connaître leur comportement et répondre à notre curiosité pour savoir le mieux que la ville nous offre de manière intelligente avec BigData et Data Science.

Bibliothèques Python

In [1]:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, TimeoutException, ElementNotInteractableException, ElementClickInterceptedException
from tqdm import tqdm_notebook as tqdmn
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import folium
import time, re

Nous extrayons les données pour les analyser

In [10]:
resto = pd.read_csv('lyon_resto.csv')
In [11]:
resto.head()
Out[11]:
full_name rating total_ratings business_category price_range address phone website review_topics hours latitude longitude
0 Canaima Restaurant 5.0 (40) Restaurant NaN QR9M+WP Lyon, France NaN +33 9 87 05 87 25 ['cuisine\n11', 'service\n3'] [] 45.769869 4.834309
1 Tipico - Restaurant & Épicerie Conviviale 5.0 (62) Italian restaurant NaN QR9H+7J Lyon, France NaN +33 4 72 02 29 91 ['entrees\n4', 'wine\n4', 'patterns\n3', 'hear... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.768148 4.829084
2 POP KORNER 4.9 (90) Restaurant NaN QRCM+FJ Lyon, France NaN +33 4 69 84 55 76 ['concept\n18', 'cinema\n14', 'room\n8', 'blin... ['% busy at .', '% busy at .', '% busy at .', ... 45.771130 4.834113
3 L'Atelier des Augustins 4.7 (275) French restaurant $$ QR9J+39 Lyon, France NaN +33 4 72 00 88 01 ['surprise\n38', 'wine\n37', 'chef\n22', 'food... [] 45.767739 4.830911
4 BEL AMI 4.7 (155) Restaurant NaN QR9J+F3 Lyon, France NaN NaN ['tapas\n25', 'cuisine\n14', 'wine list\n10', ... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.768699 4.830235
In [12]:
resto.shape
Out[12]:
(199, 12)

Cette technique de Geo Datamining nous permet d'extraire les données de 199 restaurants de la ville de Lyon

In [13]:
resto.total_ratings = resto.total_ratings.replace('(\(|\)|,)', '', regex=True)
In [14]:
resto.total_ratings = resto.total_ratings.astype(float)
In [15]:
resto.business_category.value_counts()
Out[15]:
Restaurant                        73
French restaurant                 41
Lebanese restaurant                6
Haute French restaurant            5
Fast food restaurant               4
Italian restaurant                 4
Japanese restaurant                4
Pizza restaurant                   3
Mexican restaurant                 3
Brasserie                          2
American restaurant                2
Asian restaurant                   2
Vegan restaurant                   2
Bar                                2
Down home cooking restaurant       2
Indian restaurant                  2
Modern French restaurant           2
Vegetarian restaurant              2
Moroccan restaurant                2
Hamburger restaurant               2
Seafood restaurant                 1
Hot pot restaurant                 1
Pizza takeaway                     1
Alsace restaurant                  1
Fine dining restaurant             1
Tapas bar                          1
Korean restaurant                  1
African restaurant                 1
Fondue restaurant                  1
Eastern European restaurant        1
Conveyor belt sushi restaurant     1
Pub                                1
Wine store                         1
Cambodian restaurant               1
Indonesian restaurant              1
Vietnamese restaurant              1
Wine bar                           1
Sandwich shop                      1
Juice shop                         1
Ice cream shop                     1
Soup restaurant                    1
Self service restaurant            1
Thai restaurant                    1
Beer hall                          1
中餐馆                                1
Canadian restaurant                1
Cheese shop                        1
Ramen restaurant                   1
Sushi restaurant                   1
Brewery                            1
Syrian restaurant                  1
Name: business_category, dtype: int64

Nous voulons conserver uniquement les établissements qui sont des steakhouses, des bars et des grillades ou des restaurants ayant le nom «steak» ou «grill» dans leurs noms. Appelons ce nouveau dataframe SBR (pour les Steakhouses, les Bar & Grills et les Restaurants):

Nous localiserons notre échantillon de 199 restaurants à Lyon

In [16]:
tileset = r'https://api.mapbox.com/styles/v1/roqueleal08/cjyaey84d07zq1crze5r08yg1/tiles/256/{z}/{x}/{y}@2x?access_token=pk.APIMAPBOX'
attribution = (r'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a>'
                ' contributors, Imagery © <a href="http://mapbox.com">MapBox</a>')
gdl_center = [45.756146,4.835014]
resto_map = folium.Map(location=gdl_center, zoom_start=12.5, tiles=tileset, attr=attribution)

for latitude, longitude, full_name, address, phone, website, rating, total_rating in zip(resto.latitude, resto.longitude, resto.full_name, resto.address, resto.phone, resto.website, resto.rating, resto.total_ratings):
    popup = '<strong>' + str(full_name) +  '</li><li>Rating: ' + str(rating) + ' (Total of ' + str(total_rating) + ' reviews)'
    folium.Marker( [latitude, longitude], 
                   icon=folium.CustomIcon( icon_image='https://www.pinclipart.com/picdir/big/46-460577_maps-vector-graphic-google-maps-icon-android-clipart.png', icon_size=(15,15) ), popup=popup).add_to(resto_map)
resto_map
Out[16]:
In [17]:
from folium.plugins import HeatMap
resto_rating = resto[resto.total_ratings>400].copy()
resto_rating['count'] = 1

Nous faisons un Heatmap avec les restaurants avec le meilleur score de reviews de la ville

In [18]:
HeatMap(data=resto_rating[['latitude', 'longitude', 'count']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), radius=20, max_zoom=17).add_to(resto_map)
resto_map
Out[18]:
In [24]:
resto_rating.head().sort_values(by='total_ratings', ascending=False)
Out[24]:
full_name rating total_ratings business_category price_range address phone website review_topics hours latitude longitude count
25 YAAFA 4.4 987.0 Fast food restaurant NaN NaN yaafa.fr QR9J+2M Lyon, France ['delivery\n4', 'falafel\n174', 'corn\n29', 'r... ['0% busy at 6 AM.', '0% busy at 7 AM.', '0% b... 45.767578 4.831731 1
15 Le Bouchon des Filles 4.4 789.0 Restaurant $$ QR9H+FP Lyon, France NaN +33 4 78 30 40 44 ['food presentation\n60', 'entree\n50', 'lyonn... ['0% busy at 6 AM.', '0% busy at 7 AM.', '0% b... 45.768673 4.829360 1
16 Delicatessen 4.6 626.0 Restaurant $$ NaN facebook.com QR9H+QV Lyon, France ['concept\n71', 'amateur\n23', 'weight\n17', '... ['% busy at .', '0% busy at 6 AM.', '0% busy a... 45.769481 4.829663 1
5 La Mère Brazier 4.7 574.0 Restaurant $$$$ QRCP+HV Lyon, France NaN +33 4 78 23 17 20 ['food presentation\n66', 'corn\n21', 'sommeli... [] 45.771443 4.837213 1
14 La Tête De Lard 4.4 501.0 Restaurant $$ QR9P+86 Lyon, France NaN +33 4 78 27 96 80 ['bouchon\n95', 'food presentation\n23', 'entr... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.768369 4.835512 1

Maintenant, nous identifions les restaurants qui remplissent la condition d'être des restaurants de cuisine traditionnelle de haute qualité avec une bonne gamme de cocktails

Ici, nous voyons les restaurants qui remplissent les conditions décrites en fonction du sujet de leurs avis, cela fait référence aux mots clés que les utilisateurs ont reconnus et attribués à leurs "reviews". Avec ces données, nous choisissons les restaurants qui remplissent la condition de "traditionnel", "cocktail" et "présentation" pour attribuer une valeur à chaque restaurant et obtenir un score en fonction de ces conditions.

In [26]:
traditional = []
for i in resto.review_topics :
    traditional.append(re.findall('\d+|$', re.findall('traditional......|$', i)[0])[0] )

resto['traditional'] = traditional

cocktail = []
for i in resto.review_topics :
    cocktail.append(re.findall('\d+|$', re.findall('cocktail......|$', i)[0])[0] )

resto['cocktail'] = cocktail

presentation = []
for i in resto.review_topics :
    presentation.append(re.findall('\d+|$', re.findall('presentation......|$', i)[0])[0] )

resto['presentation'] = presentation
In [29]:
resto.head()
Out[29]:
full_name rating total_ratings business_category price_range address phone website review_topics hours latitude longitude traditional cocktail presentation
0 Canaima Restaurant 5.0 40.0 Restaurant NaN QR9M+WP Lyon, France NaN +33 9 87 05 87 25 ['cuisine\n11', 'service\n3'] [] 45.769869 4.834309
1 Tipico - Restaurant & Épicerie Conviviale 5.0 62.0 Italian restaurant NaN QR9H+7J Lyon, France NaN +33 4 72 02 29 91 ['entrees\n4', 'wine\n4', 'patterns\n3', 'hear... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.768148 4.829084
2 POP KORNER 4.9 90.0 Restaurant NaN QRCM+FJ Lyon, France NaN +33 4 69 84 55 76 ['concept\n18', 'cinema\n14', 'room\n8', 'blin... ['% busy at .', '% busy at .', '% busy at .', ... 45.771130 4.834113 6
3 L'Atelier des Augustins 4.7 275.0 French restaurant $$ QR9J+39 Lyon, France NaN +33 4 72 00 88 01 ['surprise\n38', 'wine\n37', 'chef\n22', 'food... [] 45.767739 4.830911 20
4 BEL AMI 4.7 155.0 Restaurant NaN QR9J+F3 Lyon, France NaN NaN ['tapas\n25', 'cuisine\n14', 'wine list\n10', ... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.768699 4.830235
In [33]:
resto.traditional = resto.traditional.replace('', 0)
resto.cocktail = resto.cocktail.replace('', 0)
resto.presentation = resto.presentation.replace('', 0)
In [34]:
resto.traditional = resto.traditional.astype(int)
resto.cocktail = resto.cocktail.astype(int)
resto.presentation = resto.presentation.astype(int)
In [36]:
resto.head()
Out[36]:
full_name rating total_ratings business_category price_range address phone website review_topics hours latitude longitude traditional cocktail presentation
0 Canaima Restaurant 5.0 40.0 Restaurant NaN QR9M+WP Lyon, France NaN +33 9 87 05 87 25 ['cuisine\n11', 'service\n3'] [] 45.769869 4.834309 0 0 0
1 Tipico - Restaurant & Épicerie Conviviale 5.0 62.0 Italian restaurant NaN QR9H+7J Lyon, France NaN +33 4 72 02 29 91 ['entrees\n4', 'wine\n4', 'patterns\n3', 'hear... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.768148 4.829084 0 0 0
2 POP KORNER 4.9 90.0 Restaurant NaN QRCM+FJ Lyon, France NaN +33 4 69 84 55 76 ['concept\n18', 'cinema\n14', 'room\n8', 'blin... ['% busy at .', '% busy at .', '% busy at .', ... 45.771130 4.834113 0 6 0
3 L'Atelier des Augustins 4.7 275.0 French restaurant $$ QR9J+39 Lyon, France NaN +33 4 72 00 88 01 ['surprise\n38', 'wine\n37', 'chef\n22', 'food... [] 45.767739 4.830911 0 0 20
4 BEL AMI 4.7 155.0 Restaurant NaN QR9J+F3 Lyon, France NaN NaN ['tapas\n25', 'cuisine\n14', 'wine list\n10', ... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.768699 4.830235 0 0 0
In [37]:
resto['score'] = resto.traditional + resto.cocktail + resto.presentation
In [38]:
resto[((resto.traditional != 0)|(resto.cocktail != 0)) & (resto.presentation != 0)].sort_values(by='score', ascending=False)
Out[38]:
full_name rating total_ratings business_category price_range address phone website review_topics hours latitude longitude traditional cocktail presentation score
31 Maison Villemanzy 4.4 352.0 French restaurant $$ QRCP+M7 Lyon, France NaN +33 4 72 98 21 21 ['food presentation\n41', 'terrace\n26', 'visi... ['% busy at .', '0% busy at 6 AM.', '0% busy a... 45.771666 4.835712 5 0 41 46
152 La Mère Jean 4.4 656.0 French restaurant $$ QR4M+WX Lyon, France NaN +33 4 78 37 81 27 ['bouchon\n124', 'food presentation\n31', 'lyo... ['% busy at .', '0% busy at 6 AM.', '0% busy a... 45.757263 4.834922 9 0 31 40
85 Butcher 4.4 468.0 Restaurant $$ QR8J+5Q Lyon, France NaN +33 9 50 76 46 82 ['burger\n52', 'corn\n34', 'food presentation\... ['0% busy at 6 AM.', '0% busy at 7 AM.', '0% b... 45.765452 4.831978 0 19 20 39
135 Copper Roots 4.5 103.0 Restaurant NaN QRGP+PF Lyon, France NaN +33 4 72 07 64 30 ['cocktails\n32', 'brunch\n13', 'cuisine\n11',... ['0% busy at 6 AM.', '0% busy at 7 AM.', '0% b... 45.776758 4.836198 0 32 7 39
101 Bouchon Tupin 4.8 366.0 French restaurant $$ QR7M+5X Lyon, France NaN +33 4 78 37 45 93 ['food presentation\n29', 'server\n18', 'parfa... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.762878 4.834945 8 0 29 37
50 Mas amor por favor 4.2 186.0 Restaurant $$ NaN masamorporfavor-lyon.com QR9J+X3 Lyon, France ['brunch\n27', 'cocktails\n27', 'cuisine\n14',... [] 45.769906 4.830210 0 27 5 32
9 Sabaï Sabaï 4.7 166.0 Asian restaurant $$ NaN sabaisabai.fr QR9P+PM Lyon, France ['tapas\n31', 'food presentation\n17', 'cockta... ['% busy at .', '0% busy at 6 AM.', '0% busy a... 45.769259 4.836668 0 13 17 30
127 Restaurant El Cafetero 4.6 200.0 Restaurant $$ QRCX+2P Lyon, France NaN NaN ['food presentation\n20', 'mojito\n11', 'colom... [] 45.770115 4.849329 0 6 20 26
78 Le Passage 4.4 217.0 Restaurant $$ QR8M+9G Lyon, France NaN +33 4 78 28 11 16 ['cuisine\n18', 'food presentation\n14', 'cock... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.765999 4.833757 0 9 14 23
28 Hemingway's 4.3 235.0 Restaurant $$ NaN hemingways.fr QRCP+5Q Lyon, France ['cuisine\n14', 'cocktails\n13', 'server\n12',... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.770390 4.836936 0 13 9 22
144 Le Bouchon des Berges 4.5 262.0 Restaurant $$ QR5R+PQ Lyon, France NaN +33 4 78 62 69 88 ['food presentation\n16', 'server\n12', 'entre... ['% busy at .', '% busy at .', '0% busy at 6 A... 45.759265 4.841896 5 0 16 21
95 Le Ti'Punch de la Réunion 4.3 133.0 Restaurant $$ NaN letipunch.fr QR8M+44 Lyon, France ['server\n10', 'cuisine of reunion island\n9',... ['% busy