Assignment 3

Author

Your Name

Published

September 13, 2024

Instructions

Complete the questions by adding the code under the relevant chunks.

Please submit your assignment as html file to me via email. Please call your assignment: “yourlastname_assignment3.html”. For example, I would submit something called “popescu_assignment3.html”. Please make sure that it is all in lower case.

To obtain the same look as this template, make sure that your you assignment preamble or YAML looks like below:

---
title: "Assignment 3"
author: "Your Name"
date: "September 13, 2024"
format:
  html:
    toc: true
    number-sections: true
    colorlinks: true
    smooth-scroll: true
    embed-resources: true
---

Note that Headers such as “Question” need to be marked with # (i.e # Question will appear as header in bold and larger font after you render the document. It will thus appear in the Table of Contents). Regular text can just be written one line underneath.

reticulate::use_python("/opt/anaconda3/bin/python", required = TRUE)

1 Question

Download the following dataset and load it into your computer’s memory.

This can be particularly useful in the context of long customer reviews.

2 Question

Add a new column with the number of words per review and print the first 3 entries. Your entries should look like below:

index profile_name rating rating_date title review_text word_count
0 J.F. Carroll 5.0 out of 5 stars Reviewed in the United States on May 6, 2024 5.0 out of 5 stars\nIt's a PS5, everyone wants one, was there any doubt?\n \nNobody could get their hands on this until just recently. It's a PS5, the craftmanship is awesome.Operates well, system works well with store, everything is easy, this console is a masterpiece and I keep it close. Haven't got into too many games yet. It looks sexy as heck, it looks dumb in ads but in real life it's fantastic looking. And you can buy sexy plates for it as well.Controller feels great. Considering the upgrade controller, but I haven't decided. The game choices are phenomenal. It's official: XBOX lost, buy a Playstation.Playstation all the way.\n 95
1 Brandon 5.0 out of 5 stars Reviewed in the United States on April 17, 2024 5.0 out of 5 stars\nGreat Product, Great Price, Great Games!\n \nI was looking for a great deal. Luckily, I found this product on sale for $450! I love this new PlayStation 5! I've been waiting years to get my own and now I have it! I use it vertically instead of horizontally, so I had to buy a vertical stand for an extra $20. Overall, I would recommend you buy this!\n 61
2 Brock 5.0 out of 5 stars Reviewed in the United States on May 5, 2024 5.0 out of 5 stars\nAmazing Console\n \nAfter using the playstation for over 4 months; I can say, this is one of the best consoles I’ve played on. I had an Xbox Series S and after playing on the PS5 there is a world of difference in graphics, FPS, and loading times. Also the spiderman game that comes with this model is spectacular.\n 56

3 Question

How many words are there in the document-feature matrix? Write relevant code so that you obtain the following output:

Number of words: 1326

4 Question

How many documents are there in the document-feature matrix? Write code so that you obtain the following.

Number of documents: 100

5 Question

Create a barplot showing the profile names with the highest word count. Your barplot should look like below.

6 Question

What are the most common 15 words? Your barplot should look like this.

7 Question

Calculate the sparsity of all the documents. Your result should be:

0.9735746606334842

8 Question

What are the most common 15 words after cleaning the text?
Make sure that you follow these steps:
Step1: Turning words to Lowercase
Step2: Removing Punctuation
Step3: Removing Stopwords
Step4: Removing Numbers
Step5: Tokenization
Step6: Lemmatization
Step7: Stemming

Your graph should look like below:

9 Question

Use OpenAI API to summarize customer reviews that are longer than 20 words. Ignore the reviews that have less than 20 words already. Print the first 5 summary reviews.

profile_name rating rating_date title review_text word_count summary
0 J.F. Carroll 5.0 out of 5 stars Reviewed in the United States on May 6, 2024 5.0 out of 5 stars\nIt's a PS5, everyone wants one, was there any doubt?\n \nNobody could get their hands on this until just recently. It's a PS5, the craftmanship is awesome.Operates well, system works well with store, everything is easy, this console is a masterpiece and I keep it close. Haven't got into too many games yet. It looks sexy as heck, it looks dumb in ads but in real life it's fantastic looking. And you can buy sexy plates for it as well.Controller feels great. Considering the upgrade controller, but I haven't decided. The game choices are phenomenal. It's official: XBOX lost, buy a Playstation.Playstation all the way.\n 95 PS5 is finally in my hands. Craftsmanship is awesome, operates well, easy to use. Looks fantastic in real life. Playstation all the way.
1 Brandon 5.0 out of 5 stars Reviewed in the United States on April 17, 2024 5.0 out of 5 stars\nGreat Product, Great Price, Great Games!\n \nI was looking for a great deal. Luckily, I found this product on sale for $450! I love this new PlayStation 5! I've been waiting years to get my own and now I have it! I use it vertically instead of horizontally, so I had to buy a vertical stand for an extra $20. Overall, I would recommend you buy this!\n 61 Got a great deal on sale for $450! Love my new PlayStation 5, had to buy a $20 vertical stand. Highly recommend!
2 Brock 5.0 out of 5 stars Reviewed in the United States on May 5, 2024 5.0 out of 5 stars\nAmazing Console\n \nAfter using the playstation for over 4 months; I can say, this is one of the best consoles I’ve played on. I had an Xbox Series S and after playing on the PS5 there is a world of difference in graphics, FPS, and loading times. Also the spiderman game that comes with this model is spectacular.\n 56 PS5 is the best console I've played on. Graphics, FPS, and loading times are superior to Xbox Series S. Spiderman game is spectacular.
3 Whispering Whiskers 5.0 out of 5 stars Reviewed in the United States on March 18, 2024 5.0 out of 5 stars\nEmbarking on a Next-Gen Adventure: An Honest Review of the PS5 Bundle\n \nGreetings, fellow gamers! Gather 'round as I recount my leap into the realm of PlayStation with the illustrious PS5 Bundle. As someone who's long been immersed in the world of Xbox, I couldn't resist the allure of Sony's latest offering, and boy, am I glad I made the jump.Let's kick things off with a nod to the PS5's design. This thing is a marvel to behold, sleek and futuristic, commanding attention in my entertainment setup like a true centerpiece. And with a whopping 1TB of SSD storage, I've got all the room I need for my ever-expanding library of games, without having to endure those dreaded load times.Now, onto the real meat of the matter – the performance. The PS5 doesn't pull any punches, delivering jaw-dropping 4K visuals and buttery-smooth frame rates that breathe new life into every game I play. And let's talk about that SSD – it's like greased lightning, ensuring I spend less time waiting and more time doing what I love: gaming.But hold onto your controllers, because the real star of the show is the DualSense. This thing is a game-changer in every sense of the word, with its immersive haptic feedback and adaptive triggers that elevate every gaming experience to new heights. And with backward compatibility, I can revisit old favorites with a fresh perspective, like catching up with old friends over a round of drinks.Of course, no review would be complete without addressing a few bumps along the road. The limited storage space is a bit of a downer, especially in today's world of massive game downloads. And let's not forget the price tag – while the PS5 is worth every penny in my book, it's definitely an investment.And then there's the hunt for the elusive console itself. Scouring the internet for availability felt like navigating a labyrinth, but let me tell you, the payoff was worth it. Sure, the PS5's size might be a tad imposing for some setups, but once you fire up that first game, you'll forget all about it.In conclusion, the PS5 Bundle has exceeded my wildest expectations, converting this die-hard Xbox fan into a true believer. So if you're on the fence, take the plunge – you won't regret it. Happy gaming, folks!\n 374 PS5 Bundle: Sleek design, fast SSD, stunning 4K visuals, immersive DualSense, limited storage, high price, worth the investment. Happy gaming!
4 Carson Morby 5.0 out of 5 stars Reviewed in the United States on May 8, 2024 5.0 out of 5 stars\nI finally go one!\n \nFinally I got a PS5! I've been waiting forever, but I made the purchase because I heard NCAA Football 24 isn't coming out on PS4. Yep. I literally upgraded for that reason only :) So far it has been super easy to use. Navigation is pretty similar to the PS4 so there hasn't been much of an adjustment. The controller battery lasts wayyyyy longer than the ps4 controllers. The image is crystal clear, especially where I have it paired with a Sony TV. Can't ask for better quality than that.It runs quiet, and I literally have no complaints about the PS5. I'm excited to playing around and experiences more!\n 109 Got a PS5 for NCAA Football 24. Easy to use, long battery life, clear image, quiet, no complaints. Excited to explore more!

10 Question

Calculate the Euclidean distance among the customer reviews. Print out the top two most similar customer reviews. Your output should look like:


**Similar Review Pair:**
Review 1:

I love it


Review 2:

Kids love it



**Similar Review Pair:**
Review 1:

👍🏻👍🏻👍🏻


Review 2:

Nice

11 Question

Now calculate the cosine similarity. Your output should look like:


**Most Similar Review Pair 1 (Cosine Similarity: 0.7487)**
Review 1:

best purchase yet


Review 2:

The best



**Most Similar Review Pair 2 (Cosine Similarity: 0.5471)**
Review 1:

Kids love it


Review 2:

I love it

12 Question

What is the difference between Euclidean Distance and Cosine Similarity? What are some caveats associated with using Euclidean Distance? What about Cosine Similarity?

13 Question

Make a wordcloud with all the customer reviews with the clean text unsing quanteda. Your output should look like below: