Professional Documents
Culture Documents
Peer Graded Assignment
Peer Graded Assignment
Worksheet
This is a 2-part assignment. In the first part, you are asked a series of
questions that will help you profile and understand the data just like a data
scientist would. For this first part of the assignment, you will be assessed
both on the correctness of your findings, as well as the code you used to
arrive at your answer. You will be graded on how easy your code is to read, so
remember to use proper formatting and comments where necessary.
In the second part of the assignment, you are asked to come up with your own
inferences and analysis of the data for a particular research question you
want to answer. You will be required to prepare the dataset for the analysis
you choose to do. As with the first part, you will be graded, in part, on how
easy your code is to read, so use proper formatting and comments to illustrate
and communicate your intent as required.
For both parts of this assignment, use this "worksheet." It provides all the
questions you are being asked, and your job will be to transfer your answers
and SQL coding where indicated into this worksheet so that your peers can
review your work. You should be able to use any Text Editor (Windows Notepad,
Apple TextEdit, Notepad ++, Sublime Text, etc.) to copy and paste your
answers. If you are going to use Word or some other page layout application,
just be careful to make sure your answers and code are lined appropriately.
In this case, you may want to save as a PDF to ensure your formatting remains
intact for you reviewer.
1. Profile the data by finding the total number of records for each of the
tables below:
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
ii. Hours = 1562
iii. Category = 2643
iv. Attribute = 1115
v. Review = 10000
vi. Checkin = 493
vii. Photo = 10000
viii. Tip = 537
ix. User = 10000
x. Friend = 11
xi. Elite_years = 2780
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
4. For each table and column listed below, display the smallest (minimum),
largest (maximum), and average (mean) value for the following fields:
+-----------------+-------------------+
| 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)
i. Avon
Copy and Paste the Resulting Table Below (2 columns – star rating and
count):
+-------+-----------+
| stars | count(id) |
+-------+-----------+
| 1.5 | 1 |
| 2.5 | 2 |
| 3.5 | 3 |
| 4.0 | 2 |
| 4.5 | 1 |
| 5.0 | 1 |
+-------+-----------+
ii. Beachwood
Copy and Paste the Resulting Table Below (2 columns – star rating and
count):
+-------+-----------+
| stars | count(id) |
+-------+-----------+
| 2.0 | 1 |
| 2.5 | 1 |
| 3.0 | 2 |
| 3.5 | 2 |
| 4.0 | 1 |
| 4.5 | 2 |
| 5.0 | 5 |
+-------+-----------+
+--------+--------------+
| name | review_count |
+--------+--------------+
| Gerald | 2000 |
| Sara | 1629 |
| Yuri | 1339 |
+--------+--------------+
At first, if look at the top reviewers and the corresponding number of fans,
you'll think that there is no correlation, since the number of fans varies a
lot. However, with this query:
+-----------------+----------------+
| reviews_segment | avg(fans) |
+-----------------+----------------+
| 0.0 | 0.431101739589 |
| 100.0 | 8.91335740072 |
| 200.0 | 18.6037735849 |
| 300.0 | 24.8035714286 |
| 400.0 | 31.5714285714 |
| 500.0 | 32.8461538462 |
| 600.0 | 76.0 |
| 700.0 | 58.0 |
| 800.0 | 97.5714285714 |
| 900.0 | 236.0 |
| 1000.0 | 104.0 |
| 1100.0 | 163.5 |
| 1200.0 | 113.5 |
| 1300.0 | 76.0 |
| 1600.0 | 50.0 |
| 2000.0 | 253.0 |
+-----------------+----------------+
Here we see that users with 0 reviews have only 0.43 fans on average; up to
500 reviews, the more reviews you leave, the more fans you get.
After that we have some exceptions with less fans for more reviews, but they
may be caused by outliers. In general, the number of fans keeps increasing.
If we reduce the precision by decreasing the number of segments, wee see that
with one exception (segment with ~1500 reviews) all other segments follow the
rule: more reviews = more fans.
+-----------------+---------------+
| reviews_segment | avg(fans) |
+-----------------+---------------+
| 0.0 | 1.08551045016 |
| 500.0 | 76.4 |
| 1000.0 | 122.333333333 |
| 1500.0 | 50.0 |
| 2000.0 | 253.0 |
+-----------------+---------------+
9. Are there more reviews with the word "love" or with the word "hate" in
them?
+-----------+------+
| name | fans |
+-----------+------+
| Amy | 503 |
| Mimi | 497 |
| Harald | 311 |
| Gerald | 253 |
| Christine | 173 |
| Lisa | 159 |
| Cat | 133 |
| William | 126 |
| Fran | 124 |
| Lissa | 120 |
+-----------+------+
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.
Yes: business with lower rating are open for longer time.
ii. Do the two groups you chose to analyze have a different number of reviews?
We can not make any conclusion based on the reviews, they vary a lot (e.g. 4
stars — 90 reviews on average, 5 stars — 13).
iii. Are you able to infer anything from the location data provided between
these two groups? Explain.
Yes: for the category I picked, some cities had a higher average rating than
others.
Due to the outdated version of SQLite in this course, I had to use a very
complex code to compute the total number of hours the business is open:
replace(replace(replace(replace(replace(replace(replace(hours,
'Sunday|', ''),
'Saturday|', ''), 'Friday|', ''), 'Thursday|',
''), 'Wednesday|', ''), 'Tuesday|', ''),
'Monday|', '') as hours
from hours)))
group by business_id)
left join business on business_id = id
where city = 'Las Vegas'
group by stars
and
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:
ii. Difference 2:
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:
Find out which attributes are the most important ones to improve in order to
increase the ratings.
ii. Write 1-2 brief paragraphs on the type of data you will need for your
analysis and why you chose that data:
I'm going to use two tables: business and attribute. I'll join them together
and compute various statistics on the result.
For example, I'll choose only the binary attributes (with values 0 or 1) to
join to the business table, and I'll filter out the business with value = 1
(where the attribute exists, e.g. dogs are accepted etc). Then, I'll group the
businesses by their attribute and compute their average rating. I'll observe
which attributes have a higher rating — maybe these attributes are important
for customers.
I'll confirm these observations by comparing the result to the similar table
with value = 0.
+----------------------------+---------------+---------------+
| name | value1_stars | value0_stars |
+----------------------------+---------------+---------------+
| AcceptsInsurance | 4.21428571429 | 4.5 |
| BikeParking | 3.51515151515 | 3.64285714286 |
| BusinessAcceptsCreditCards | 3.68571428571 | 3.875 |
| ByAppointmentOnly | 4.19230769231 | 4.22222222222 |
| Caters | 3.6 | 3.20833333333 |
| DogsAllowed | 3.5 | 4.0 |
| GoodForKids | 3.41666666667 | 3.125 |
| HasTV | 3.20588235294 | 3.30769230769 |
| OutdoorSeating | 3.275 | 2.96666666667 |
| RestaurantsDelivery | 3.0 | 3.15384615385 |
| RestaurantsGoodForGroups | 3.08333333333 | 3.0 |
| RestaurantsReservations | 3.5 | 3.06818181818 |
| RestaurantsTableService | 3.33333333333 | 3.19230769231 |
| RestaurantsTakeOut | 3.12121212121 | 4.0 |
| WheelchairAccessible | 3.43181818182 | 3.5 |
+----------------------------+---------------+---------------+
iv. Provide the SQL code you used to create your final dataset: