-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profiling and Analyzing the Yelp Dataset.txt
533 lines (390 loc) · 14.5 KB
/
Profiling and Analyzing the Yelp Dataset.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
Data Scientist Role Play: Profiling and Analyzing the Yelp Dataset
Part 1: Yelp Dataset Profiling and Understanding
1. Profile the data by finding the total number of records for each of the tables below:
i. Attribute table = 10000
SELECT COUNT(*)
FROM attribute;
ii. Business table = 10000
SELECT COUNT(*)
FROM business;
iii. Category table = 10000
SELECT COUNT(*)
FROM category;
iv. Checkin table = 10000
SELECT COUNT(*)
FROM checkin;
v. elite_years table = 10000
SELECT COUNT(*)
FROM elite_years;
vi. friend table = 10000
SELECT COUNT(*)
FROM friend;
vii. hours table = 10000
SELECT COUNT(*)
FROM hours;
viii. photo table = 10000
SELECT COUNT(*)
FROM photo;
ix. review table = 10000
SELECT COUNT(*)
FROM review;
x. tip table = 10000
SELECT COUNT(*)
FROM tip;
xi. user table = 10000
SELECT COUNT(*)
FROM user;
2. Find the total distinct records by either the foreign key or primary key for each table. If two foreign keys are listed in the table, please specify which foreign key.
i. Business = 10000
SELECT COUNT(DISTINCT id)
FROM business;
ii. Hours = 1562
SELECT COUNT(DISTINCT business_id)
FROM hours;
iii. Category = 2643
SELECT COUNT(DISTINCT business_id)
FROM category;
iv. Attribute = 1115
SELECT COUNT(DISTINCT business_id)
FROM attribute;
v. Review = 10000, 8090, 9581
SELECT COUNT(DISTINCT id)
,COUNT(DISTINCT business_id)
,COUNT(DISTINCT user_id)
FROM review;
vi. Checkin = 493
SELECT COUNT(DISTINCT business_id)
FROM checkin;
vii. Photo = 10000, 6493
SELECT COUNT(DISTINCT id)
,COUNT(DISTINCT business_id)
FROM photo;
viii. Tip = 537, 3979
SELECT COUNT(DISTINCT user_id)
,COUNT(DISTINCT business_id)
FROM tip;
ix. User = 10000
SELECT COUNT(DISTINCT id)
FROM user;
x. Friend = 11
SELECT COUNT(DISTINCT user_id)
FROM friend;
xi. Elite_years = 2780
SELECT COUNT(DISTINCT user_id)
FROM elite_years;
Note: Primary Keys are denoted in the ER-Diagram with a yellow key icon.
3. Are there any columns with null values in the Users table? Indicate "yes," or "no."
Answer: No
SQL code used to arrive at answer:
SELECT *
FROM user
WHERE id IS NULL
OR name IS NULL
OR review_count IS NULL
OR yelping_since IS NULL
OR useful IS NULL
OR funny IS NULL
OR cool IS NULL
OR fans IS NULL
OR average_stars IS NULL
OR compliment_hot IS NULL
OR compliment_more IS NULL
OR compliment_profile IS NULL
OR compliment_cute IS NULL
OR compliment_list IS NULL
OR compliment_note IS NULL
OR compliment_plain IS NULL
OR compliment_cool IS NULL
OR compliment_funny IS NULL
OR compliment_writer IS NULL
OR compliment_photos IS NULL
4. For each table and column listed below, display the smallest (minimum), largest (maximum), and average (mean) value for the following fields:
i. Table: Review, Column: Stars
min: 1 max: 5 avg: 3.7082
SELECT min(stars)
,max(stars)
,avg(stars)
FROM review;
ii. Table: Business, Column: Stars
min: 1.0 max: 5.0 avg: 3.6549
SELECT min(stars)
,max(stars)
,avg(stars)
FROM business;
iii. Table: Tip, Column: Likes
min: 0 max: 2 avg: 0.0144
SELECT min(likes)
,max(likes)
,avg(likes)
FROM tip;
iv. Table: Checkin, Column: Count
min: 1 max: 53 avg: 1.9414
SELECT min(count) AS min
,max(count) AS max
,avg(count) AS avg
FROM checkin;
v. Table: User, Column: Review_count
min: 0 max: 2000 avg: 24.2995
SELECT min(review_count)
,max(review_count)
,avg(review_count)
FROM user;
5. List the cities with the most reviews in descending order:
SQL code used to arrive at answer:
SELECT city
,sum(review_count)
FROM business
GROUP BY city
ORDER BY sum(review_count) DESC
Copy and Paste the Result Below:
+-----------------+-------------------+
| city | sum(review_count) |
+-----------------+-------------------+
| Las Vegas | 82854 |
| Phoenix | 34503 |
| Toronto | 24113 |
| Scottsdale | 20614 |
| Charlotte | 12523 |
| Henderson | 10871 |
| Tempe | 10504 |
| Pittsburgh | 9798 |
| Montréal | 9448 |
| Chandler | 8112 |
| Mesa | 6875 |
| Gilbert | 6380 |
| Cleveland | 5593 |
| Madison | 5265 |
| Glendale | 4406 |
| Mississauga | 3814 |
| Edinburgh | 2792 |
| Peoria | 2624 |
| North Las Vegas | 2438 |
| Markham | 2352 |
| Champaign | 2029 |
| Stuttgart | 1849 |
| Surprise | 1520 |
| Lakewood | 1465 |
| Goodyear | 1155 |
+-----------------+-------------------+
(Output limit exceeded, 25 of 362 total rows shown)
6. Find the distribution of star ratings to the business in the following cities:
i. Avon
SQL code used to arrive at answer:
SELECT stars
,COUNT(stars) AS count
FROM business
WHERE city = 'Avon'
GROUP BY stars
Copy and Paste the Resulting Table Below (2 columns – star rating and count):
+-------+-------+
| stars | count |
+-------+-------+
| 1.5 | 1 |
| 2.5 | 2 |
| 3.5 | 3 |
| 4.0 | 2 |
| 4.5 | 1 |
| 5.0 | 1 |
+-------+-------+
ii. Beachwood
SQL code used to arrive at answer:
SELECT stars
,COUNT(stars) AS count
FROM business
WHERE city = 'Beachwood'
GROUP BY stars
Copy and Paste the Resulting Table Below (2 columns – star rating and count):
+-------+-------+
| stars | count |
+-------+-------+
| 2.0 | 1 |
| 2.5 | 1 |
| 3.0 | 2 |
| 3.5 | 2 |
| 4.0 | 1 |
| 4.5 | 2 |
| 5.0 | 5 |
+-------+-------+
7. Find the top 3 users based on their total number of reviews:
SQL code used to arrive at answer:
SELECT name
,sum(review_count)
FROM user
GROUP BY name
ORDER BY sum(review_count) DESC limit 3
Copy and Paste the Result Below:
+--------+-------------------+
| name | sum(review_count) |
+--------+-------------------+
| Nicole | 2397 |
| Sara | 2253 |
| Gerald | 2034 |
+--------+-------------------+
8. Does posing more reviews correlate with more fans?
No, posing more reviews does not correlate with more fans.
Please explain your findings and interpretation of the results:
SELECT name
,sum(review_count)
,sum(fans)
FROM user
GROUP BY name
ORDER BY sum(review_count) DESC
+-----------+-------------------+-----------+
| name | sum(review_count) | sum(fans) |
+-----------+-------------------+-----------+
| Nicole | 2397 | 200 |
| Sara | 2253 | 72 |
| Gerald | 2034 | 256 |
| Lisa | 2021 | 207 |
| Mark | 1945 | 156 |
| Jennifer | 1862 | 86 |
| Jen | 1744 | 148 |
| Michelle | 1737 | 133 |
| Melissa | 1678 | 104 |
| William | 1639 | 142 |
| Karen | 1625 | 123 |
| Justin | 1572 | 78 |
| Rachel | 1519 | 79 |
| Daniel | 1441 | 75 |
| Sarah | 1436 | 100 |
| Chris | 1419 | 52 |
| Jeff | 1410 | 45 |
| Mike | 1400 | 119 |
| Yuri | 1341 | 76 |
| Dan | 1333 | 44 |
| Christine | 1309 | 187 |
| John | 1264 | 46 |
| Jessica | 1248 | 116 |
| .Hon | 1246 | 101 |
| Matt | 1239 | 62 |
+-----------+-------------------+-----------+
for example, sara has 2253 reviews and only 72 fans,
while sarah has significantly fewer reviews (1436) and more fans 100.
9. Are there more reviews with the word "love" or with the word "hate" in them?
Answer:
SQL code used to arrive at answer:
SELECT count(*) AS hate_count
FROM review
WHERE TEXT LIKE '%hate%'
+------------+
| hate_count |
+------------+
| 232 |
+------------+
SELECT count(*) AS love_count
FROM review
WHERE TEXT LIKE '%love%'
+------------+
| love_count |
+------------+
| 1780 |
+------------+
10. Find the top 10 users with the most fans:
SQL code used to arrive at answer:
SELECT fans
,name
FROM user
GROUP BY fans
ORDER BY fans DESC limit 10
Copy and Paste the Result Below:
+------+-----------+
| fans | name |
+------+-----------+
| 503 | Amy |
| 497 | Mimi |
| 311 | Harald |
| 253 | Gerald |
| 173 | Christine |
| 159 | Lisa |
| 133 | Cat |
| 126 | William |
| 124 | Fran |
| 120 | Lissa |
+------+-----------+
Part 2: Inferences and Analysis
1. Pick one city and category of your choice and group the businesses in that city or category by their overall star rating. Compare the businesses with 2-3 stars to the businesses with 4-5 stars and answer the following questions. Include your code.
i. Do the two groups you chose to analyze have a different distribution of hours?
Yes, they have different distribution hours. For example, in the Food category in the city of Las Vegas, restaurants with 2-3 stars have longer hours than those with 4-5 stars.
ii. Do the two groups you chose to analyze have a different number of reviews?
Yes, they have a different number of reviews.
iii. Are you able to infer anything from the location data provided between these two groups? Explain.
No, I couldn't infer anything because two groups have different zip codes.
SQL code used for analysis:
SELECT b.name
,c.category
,b.city
,b.postal_code AS zipcode
,h.hours
,CASE
WHEN stars BETWEEN 2 AND 3 THEN '2-3 stars'
WHEN stars BETWEEN 4 AND 5 THEN '4-5 stars'
END AS rating
,b.review_count AS reviews
FROM business b
INNER JOIN hours h ON b.id = h.business_id
INNER JOIN category c ON c.business_id = b.id
WHERE city = 'Las Vegas' AND category = 'Food' AND rating IN ('2-3 stars','4-5 stars')
GROUP BY name
ORDER BY stars DESC
2. Group business based on the ones that are open and the ones that are closed. What differences can you find between the ones that are still open and the ones that are closed?
List at least two differences and the SQL code you used to arrive at your answer.
i. Difference 1: The average number of reviews was higher for open businesses than for closed businesses.
ii. Difference 2: The number of distinct business_id for the open businesses is 5 times higher than for the closed businesses and therefore the average number of reviews for the open businesses is higher.
SQL code used for analysis:
SELECT count(DISTINCT id)
,count(DISTINCT city)
,avg(stars)
,avg(review_count)
,is_open
FROM business
GROUP BY is_open
3. For this last part of your analysis, you are going to choose the type of analysis you want to conduct on the Yelp dataset and are going to prepare the data for analysis.
Ideas for analysis include: Parsing out keywords and business attributes for sentiment analysis, clustering businesses to find commonalities or anomalies between them, predicting the overall star rating for a business,
predicting the number of fans a user will have, and so on. These are just a few examples to get you started, so feel free to be creative and come up with your own problem you want to solve.
Provide answers, in-line, to all of the following:
i. Indicate the type of analysis you chose to do:
I chose to analyse whether the businesses like Coffee & Tea having the arrtibutes like 'WheelchairAccessible','OutdoorSeating' ,'DogsAllowed' and 'BusinessAcceptsCreditCards'
anyway relate to the number of stars or the review counts that they get.
ii. Write 1-2 brief paragraphs on the type of data you will need for your analysis and why you chose that data:
I used 3 tables for my analysis: Company, Category and Attribute.
I chose the name of the business, its category, the state in which it is run, the characteristics it has, its ratings and the number of its ratings.
I have variables like
1)name, state, stars , review_count from the table business,
2)category from the table category and
3)name ,value from the attribute table.
To connect all the 3 tables. I used the primary keys like id from business, business_id from category and
business_id from attribute table.
I wanted to know having a free wifi or OutdoorSeating or having BusinessAcceptsCreditCards or having WheelchairAccessible or having any combination of 3 or all the attributes
contributes to good rating or having more reviews in particular.
but what I found out was, the two businesses have same attributes, but are in two different states. The business in OH clearly has more reviews and thus more stars
iii. Output of your finished dataset:
+-------------+----------------------------+-------+-------+-------+--------------+
| business | attribute | value | state | stars | review_count |
+-------------+----------------------------+-------+-------+-------+--------------+
| Koko Bakery | WiFi | free | OH | 4.0 | 162 |
| Koko Bakery | OutdoorSeating | 0 | OH | 4.0 | 162 |
| Koko Bakery | BusinessAcceptsCreditCards | 1 | OH | 4.0 | 162 |
| Koko Bakery | WheelchairAccessible | 1 | OH | 4.0 | 162 |
| Starbucks | WiFi | free | AZ | 3.0 | 52 |
| Starbucks | OutdoorSeating | 1 | AZ | 3.0 | 52 |
| Starbucks | BusinessAcceptsCreditCards | 1 | AZ | 3.0 | 52 |
+-------------+----------------------------+-------+-------+-------+--------------+
iv. Provide the SQL code you used to create your final dataset:
SELECT b.name AS business
,att.name AS attribute
,att.value
,b.STATE
,b.stars
,b.review_count
FROM business b
INNER JOIN category c ON c.business_id = b.id
INNER JOIN attribute att ON att.business_id = b.id
WHERE (
att.name LIKE 'WiFi'
OR att.name LIKE 'WheelchairAccessible'
OR att.name LIKE 'OutdoorSeating'
OR att.name LIKE 'DogsAllowed'
OR att.name LIKE 'BusinessAcceptsCreditCards'
)
AND category = 'Coffee & Tea'
ORDER BY stars DESC