diff --git a/challenge-1.ipynb b/challenge-1.ipynb
new file mode 100644
index 0000000..3a89e38
--- /dev/null
+++ b/challenge-1.ipynb
@@ -0,0 +1,260 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 1: Prepare Textual Data for Analysis\n",
+ "\n",
+ "In this challenge, we will walk you through how to prepare raw text data for NLP analysis. Due to time limitation, we will cover **text cleaning, tokenization, stemming, lemmatization, and stop words removal** but skip POS tags, named entity recognition, and trunking. The latter 3 steps are more advanced and not required for our next challenge on sentiment analysis. \n",
+ "\n",
+ "## Objectives\n",
+ "\n",
+ "* Learn how to prepare text data for NLP analysis in Python\n",
+ "* Write the functions you will use in Challenge 3 for cleaning, tokenizing, stemming, and lemmatizing data."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Text Cleaning\n",
+ "\n",
+ "Text cleaning is also called text cleansing. The goal is to clean up the messy real-world textual data in order to improve the text analysis accuracy at later steps. For generic textual data sources, we usually need to fix the following problems:\n",
+ "\n",
+ "* Missing values\n",
+ "* Special characters\n",
+ "* Numbers\n",
+ "\n",
+ "For web data, we need to additinally fix:\n",
+ "\n",
+ "* HTML tags\n",
+ "* JavaScripts\n",
+ "* CSS\n",
+ "* URLs\n",
+ "\n",
+ "Case by case, there may also be special problems we need to fix for certain types of data. For instance, for Twitter tweets data we need to fix hashtags and the Twitter handler including a *@* sign and Twitter usernames.\n",
+ "\n",
+ "In addition, we also need to convert the texts to lower cases so that when we anaylize the words later, NLTK will not think *Ironhack* and *ironhack* mean different things.\n",
+ "\n",
+ "Note that the above are the general steps to clean up data for NLP analysis. In specific cases, not all those steps apply. For example, if you are analyzing textual data on history, you probably don't want to remove numbers because numbers (such as years and dates) are important in history. Besides, if you are doing something like network analysis on web data, you may want to retain hyperlinks so that you will be able to extract the outbounding links in the next steps. Sometimes you may also need to do some cleaning first, then extract some features, then do more cleaning, then extract more features. You'll have to make these judgments by yourself case by case. \n",
+ "\n",
+ "In this challenge we are keeping things relatively simple so **you only need to clean up special characters, numbers, and URLs**. Let's say you have the following messy string to clean up:\n",
+ "\n",
+ "```\n",
+ "@Ironhack's-#Q website 776-is http://ironhack.com [(2018)]\")\n",
+ "```\n",
+ "\n",
+ "You will write a function, which will be part of you NLP analysis pipeline in the next challenge, to clean up strings like above and output:\n",
+ "\n",
+ "```\n",
+ "ironhack s q website is\n",
+ "```\n",
+ "\n",
+ "**In the cell below, write a function called `clean_up`**. Test your function with the above string and make sure you receive the expected output.\n",
+ "\n",
+ "*Notes:*\n",
+ "\n",
+ "* Use regular expressions to identify URL patterns and remove URLs.\n",
+ "\n",
+ "* You don't want to replace special characters/numbers with an empty string. Because that will join words that shouldn't be joined. For instance, if you replace the `'` in `you're`, you will get `youre` which is undesirable. So instead, replace special characters and numbers with a whitespace.\n",
+ "\n",
+ "* The order matters in terms of what to clean before others. For example, if you clean special characters before URLs, it will be difficult to identify the URLs patterns.\n",
+ "\n",
+ "* Don't worry about single letters and multiple whitespaces in your returned string. In our next steps those issues will be fixed."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Libraries\n",
+ "\n",
+ "import re\n",
+ "import nltk\n",
+ "from nltk.tokenize import word_tokenize\n",
+ "from nltk.stem import PorterStemmer, WordNetLemmatizer\n",
+ "from nltk.corpus import stopwords"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def clean_up(s):\n",
+ " \"\"\"\n",
+ " Cleans up numbers, URLs, and special characters from a string.\n",
+ "\n",
+ " Args:\n",
+ " s: The string to be cleaned up.\n",
+ "\n",
+ " Returns:\n",
+ " A string that has been cleaned up.\n",
+ " \n",
+ " \"\"\"\n",
+ " \n",
+ " s = re.sub(r\"http\\S+|www\\S+|https\\S+\", \"\", s)\n",
+ "\n",
+ " s = re.sub(r\"[^a-zA-Z]\", \" \", s)\n",
+ "\n",
+ " s = s.lower()\n",
+ " \n",
+ " return s"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Tokenization\n",
+ "\n",
+ "We have actually discussed the concept of tokenization in the Bag of Words lab before. In that lab, we did both tokenization and calculated the [matrix of document-term frequency](https://en.wikipedia.org/wiki/Document-term_matrix). In this lab, we only need tokenization.\n",
+ "\n",
+ "In the cell below, write a function called **`tokenize`** to convert a string to a list of words. We'll use the string we received in the previous step *`ironhack s q website is`* to test your function. Your function shoud return:\n",
+ "\n",
+ "```python\n",
+ "['ironhack', 's', 'q', 'website', 'is']\n",
+ "```\n",
+ "\n",
+ "*Hint: use the `word_tokenize` function in NLTK.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def tokenize(s):\n",
+ " \"\"\"\n",
+ " Tokenize a string.\n",
+ "\n",
+ " Args:\n",
+ " s: String to be tokenized.\n",
+ "\n",
+ " Returns:\n",
+ " A list of words as the result of tokenization.\n",
+ " \"\"\"\n",
+ " return word_tokenize(s)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Stemming and Lemmatization\n",
+ "\n",
+ "We will do stemming and lemmatization in the same step because otherwise we'll have to loop each token lists twice. You have learned in the previous challenge that stemming and lemmatization are similar but have different purposes for text normalization:\n",
+ "\n",
+ "**Stemming reduces words to their root forms (stems) even if the stem itself is not a valid word**. For instance, *token*, *tokenize*, and *tokenization* will be reduced to the same stem - *token*. And *change*, *changed*, *changing* will be reduced to *chang*.\n",
+ "\n",
+ "In NLTK, there are three stemming libraries: [*Porter*](https://www.nltk.org/_modules/nltk/stem/porter.html), [*Snowball*](https://www.nltk.org/_modules/nltk/stem/snowball.html), and [*Lancaster*](https://www.nltk.org/_modules/nltk/stem/lancaster.html). The difference among the three is the agressiveness with which they perform stemming. Porter is the most gentle stemmer that preserves the word's original form if it has doubts. In contrast, Lancaster is the most aggressive one that sometimes produces wrong outputs. And Snowball is in between. **In most cases you will use either Porter or Snowball**.\n",
+ "\n",
+ "**Lemmatization differs from stemming in that lemmatization cares about whether the reduced form belongs to the target language and it often requires the context (i.e. POS or parts-of-speech) in order to perform the correct transformation**. For example, the [*Word Net lemmatizer* in NLTK](https://www.nltk.org/_modules/nltk/stem/wordnet.html) yields different results with and without being told that *was* is a verb:\n",
+ "\n",
+ "```python\n",
+ ">>> from nltk.stem import WordNetLemmatizer\n",
+ ">>> lemmatizer = WordNetLemmatizer()\n",
+ ">>> lemmatizer.lemmatize('was')\n",
+ "'wa'\n",
+ ">>> lemmatizer.lemmatize('runs', pos='v')\n",
+ "'be'\n",
+ "```\n",
+ "\n",
+ "In the cell below, import the necessary libraries and define a function called `stem_and_lemmatize` that performs both stemming and lemmatization on a list of words. Don't worry about the POS part of lemmatization for now."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def stem_and_lemmatize(l):\n",
+ " \"\"\"\n",
+ " Perform stemming and lemmatization on a list of words.\n",
+ "\n",
+ " Args:\n",
+ " l: A list of strings.\n",
+ "\n",
+ " Returns:\n",
+ " A list of strings after being stemmed and lemmatized.\n",
+ " \"\"\"\n",
+ " \n",
+ " stemmer = PorterStemmer()\n",
+ " lemmatizer = WordNetLemmatizer()\n",
+ " \n",
+ " return [stemmer.stem(lemmatizer.lemmatize(word)) for word in l]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Stop Words Removal\n",
+ "\n",
+ "Stop Words are the most commonly used words in a language that don't contribute to the main meaning of the texts. Examples of English stop words are `i`, `me`, `is`, `and`, `the`, `but`, and `here`. We want to remove stop words from analysis because otherwise stop words will take the overwhelming portion in our tokenized word list and the NLP algorithms will have problems in identifying the truely important words.\n",
+ "\n",
+ "NLTK has a `stopwords` package that allows us to import the most common stop words in over a dozen langauges including English, Spanish, French, German, Dutch, Portuguese, Italian, etc. These are the bare minimum stop words (100-150 words in each language) that can get beginners started. Some other NLP packages such as [*stop-words*](https://pypi.org/project/stop-words/) and [*wordcloud*](https://amueller.github.io/word_cloud/generated/wordcloud.WordCloud.html) provide bigger lists of stop words.\n",
+ "\n",
+ "Now in the cell below, create a function called `remove_stopwords` that loop through a list of words that have been stemmed and lemmatized to check and remove stop words. Return a new list where stop words have been removed."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def remove_stopwords(l):\n",
+ " \"\"\"\n",
+ " Remove English stopwords from a list of strings.\n",
+ "\n",
+ " Args:\n",
+ " l: A list of strings.\n",
+ "\n",
+ " Returns:\n",
+ " A list of strings after stop words are removed.\n",
+ " \"\"\"\n",
+ " \n",
+ " stop_words = set(stopwords.words('english'))\n",
+ " \n",
+ " return [word for word in l if word not in stop_words]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Summary\n",
+ "\n",
+ "In this challenge you have learned several text preparation techniques in more depths including text cleaning, tokenization, stemming, lemmatization, and stopwords removal. You have also written the functions you will be using in the next challenge to prepare texts for NLP analysis. Now we are ready to move on to the next challenge - Sentiment Analysis."
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.12"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/challenge-2.ipynb b/challenge-2.ipynb
new file mode 100644
index 0000000..562ddb1
--- /dev/null
+++ b/challenge-2.ipynb
@@ -0,0 +1,2735 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 2: Sentiment Analysis\n",
+ "\n",
+ "In this challenge we will learn sentiment analysis and practice performing sentiment analysis on Twitter tweets. \n",
+ "\n",
+ "## Introduction\n",
+ "\n",
+ "Sentiment analysis is to *systematically identify, extract, quantify, and study affective states and subjective information* based on texts ([reference](https://en.wikipedia.org/wiki/Sentiment_analysis)). In simple words, it's to understand whether a person is happy or unhappy in producing the piece of text. Why we (or rather, companies) care about sentiment in texts? It's because by understanding the sentiments in texts, we will be able to know if our customers are happy or unhappy about our products and services. If they are unhappy, the subsequent action is to figure out what have caused the unhappiness and make improvements.\n",
+ "\n",
+ "Basic sentiment analysis only understands the *positive* or *negative* (sometimes *neutral* too) polarities of the sentiment. More advanced sentiment analysis will also consider dimensions such as agreement, subjectivity, confidence, irony, and so on. In this challenge we will conduct the basic positive vs negative sentiment analysis based on real Twitter tweets.\n",
+ "\n",
+ "NLTK comes with a [sentiment analysis package](https://www.nltk.org/api/nltk.sentiment.html). This package is great for dummies to perform sentiment analysis because it requires only the textual data to make predictions. For example:\n",
+ "\n",
+ "```python\n",
+ ">>> from nltk.sentiment.vader import SentimentIntensityAnalyzer\n",
+ ">>> txt = \"Ironhack is a Global Tech School ranked num 2 worldwide.
",
+ "
",
+ "Our mission is to help people transform their careers and join a thriving community of tech professionals that love what they do.\"\n",
+ ">>> analyzer = SentimentIntensityAnalyzer()\n",
+ ">>> analyzer.polarity_scores(txt)\n",
+ "{'neg': 0.0, 'neu': 0.741, 'pos': 0.259, 'compound': 0.8442}\n",
+ "```\n",
+ "\n",
+ "In this challenge, however, you will not use NLTK's sentiment analysis package because in your Machine Learning training in the past 2 weeks you have learned how to make predictions more accurate than that. The [tweets data](https://www.kaggle.com/kazanova/sentiment140) we will be using today are already coded for the positive/negative sentiment. You will be able to use the Naïve Bayes classifier you learned in the lesson to predict the sentiment of tweets based on the labels."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Conducting Sentiment Analysis\n",
+ "\n",
+ "### Loading and Exploring Data\n",
+ "\n",
+ "The dataset we'll be using today is located on Kaggle (https://www.kaggle.com/kazanova/sentiment140). Once you have downloaded and imported the dataset, it you will need to define the columns names: df.columns = ['target','id','date','flag','user','text']\n",
+ "\n",
+ "*Notes:* \n",
+ "\n",
+ "* The dataset is huuuuge (1.6m tweets). When you develop your data analysis codes, you can sample a subset of the data (e.g. 20k records) so that you will save a lot of time when you test your codes."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 83,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# libraries\n",
+ "import pandas as pd\n",
+ "import re\n",
+ "import numpy as np\n",
+ "\n",
+ "import nltk\n",
+ "from nltk.tokenize import word_tokenize\n",
+ "from sklearn.feature_extraction.text import CountVectorizer\n",
+ "from nltk.stem import PorterStemmer\n",
+ "from nltk.stem import WordNetLemmatizer\n",
+ "from nltk.corpus import stopwords\n",
+ "from nltk import FreqDist\n",
+ "from langdetect import detect\n",
+ "from nltk.corpus import movie_reviews\n",
+ "from nltk.sentiment import SentimentIntensityAnalyzer\n",
+ "\n",
+ "import random\n",
+ "from nltk.corpus import movie_reviews\n",
+ "from nltk.classify import apply_features"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " target | \n",
+ " id | \n",
+ " date | \n",
+ " flag | \n",
+ " user | \n",
+ " text | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 0 | \n",
+ " 1467810672 | \n",
+ " Mon Apr 06 22:19:49 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " scotthamilton | \n",
+ " is upset that he can't update his Facebook by ... | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 0 | \n",
+ " 1467810917 | \n",
+ " Mon Apr 06 22:19:53 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " mattycus | \n",
+ " @Kenichan I dived many times for the ball. Man... | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 0 | \n",
+ " 1467811184 | \n",
+ " Mon Apr 06 22:19:57 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " ElleCTF | \n",
+ " my whole body feels itchy and like its on fire | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 0 | \n",
+ " 1467811193 | \n",
+ " Mon Apr 06 22:19:57 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " Karoli | \n",
+ " @nationwideclass no, it's not behaving at all.... | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 0 | \n",
+ " 1467811372 | \n",
+ " Mon Apr 06 22:20:00 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " joy_wolf | \n",
+ " @Kwesidei not the whole crew | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 1599994 | \n",
+ " 4 | \n",
+ " 2193601966 | \n",
+ " Tue Jun 16 08:40:49 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " AmandaMarie1028 | \n",
+ " Just woke up. Having no school is the best fee... | \n",
+ "
\n",
+ " \n",
+ " | 1599995 | \n",
+ " 4 | \n",
+ " 2193601969 | \n",
+ " Tue Jun 16 08:40:49 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " TheWDBoards | \n",
+ " TheWDB.com - Very cool to hear old Walt interv... | \n",
+ "
\n",
+ " \n",
+ " | 1599996 | \n",
+ " 4 | \n",
+ " 2193601991 | \n",
+ " Tue Jun 16 08:40:49 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " bpbabe | \n",
+ " Are you ready for your MoJo Makeover? Ask me f... | \n",
+ "
\n",
+ " \n",
+ " | 1599997 | \n",
+ " 4 | \n",
+ " 2193602064 | \n",
+ " Tue Jun 16 08:40:49 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " tinydiamondz | \n",
+ " Happy 38th Birthday to my boo of alll time!!! ... | \n",
+ "
\n",
+ " \n",
+ " | 1599998 | \n",
+ " 4 | \n",
+ " 2193602129 | \n",
+ " Tue Jun 16 08:40:50 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " RyanTrevMorris | \n",
+ " happy #charitytuesday @theNSPCC @SparksCharity... | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
1599999 rows × 6 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " target id date flag \\\n",
+ "0 0 1467810672 Mon Apr 06 22:19:49 PDT 2009 NO_QUERY \n",
+ "1 0 1467810917 Mon Apr 06 22:19:53 PDT 2009 NO_QUERY \n",
+ "2 0 1467811184 Mon Apr 06 22:19:57 PDT 2009 NO_QUERY \n",
+ "3 0 1467811193 Mon Apr 06 22:19:57 PDT 2009 NO_QUERY \n",
+ "4 0 1467811372 Mon Apr 06 22:20:00 PDT 2009 NO_QUERY \n",
+ "... ... ... ... ... \n",
+ "1599994 4 2193601966 Tue Jun 16 08:40:49 PDT 2009 NO_QUERY \n",
+ "1599995 4 2193601969 Tue Jun 16 08:40:49 PDT 2009 NO_QUERY \n",
+ "1599996 4 2193601991 Tue Jun 16 08:40:49 PDT 2009 NO_QUERY \n",
+ "1599997 4 2193602064 Tue Jun 16 08:40:49 PDT 2009 NO_QUERY \n",
+ "1599998 4 2193602129 Tue Jun 16 08:40:50 PDT 2009 NO_QUERY \n",
+ "\n",
+ " user text \n",
+ "0 scotthamilton is upset that he can't update his Facebook by ... \n",
+ "1 mattycus @Kenichan I dived many times for the ball. Man... \n",
+ "2 ElleCTF my whole body feels itchy and like its on fire \n",
+ "3 Karoli @nationwideclass no, it's not behaving at all.... \n",
+ "4 joy_wolf @Kwesidei not the whole crew \n",
+ "... ... ... \n",
+ "1599994 AmandaMarie1028 Just woke up. Having no school is the best fee... \n",
+ "1599995 TheWDBoards TheWDB.com - Very cool to hear old Walt interv... \n",
+ "1599996 bpbabe Are you ready for your MoJo Makeover? Ask me f... \n",
+ "1599997 tinydiamondz Happy 38th Birthday to my boo of alll time!!! ... \n",
+ "1599998 RyanTrevMorris happy #charitytuesday @theNSPCC @SparksCharity... \n",
+ "\n",
+ "[1599999 rows x 6 columns]"
+ ]
+ },
+ "execution_count": 27,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df = pd.read_csv(\"training.1600000.processed.noemoticon.csv\", encoding='latin1')\n",
+ "df.columns = ['target','id','date','flag','user','text']\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " target | \n",
+ " id | \n",
+ " date | \n",
+ " flag | \n",
+ " user | \n",
+ " text | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 0 | \n",
+ " 2200003313 | \n",
+ " Tue Jun 16 18:18:13 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " DEWGetMeTho77 | \n",
+ " @Nkluvr4eva My poor little dumpling In Holmde... | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 0 | \n",
+ " 1467998601 | \n",
+ " Mon Apr 06 23:11:18 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " Young_J | \n",
+ " I'm off too bed. I gotta wake up hella early t... | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 0 | \n",
+ " 2300049112 | \n",
+ " Tue Jun 23 13:40:12 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " dougnawoschik | \n",
+ " I havent been able to listen to it yet My spe... | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 0 | \n",
+ " 1993474319 | \n",
+ " Mon Jun 01 10:26:09 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " thireven | \n",
+ " now remembers why solving a relatively big equ... | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 0 | \n",
+ " 2256551006 | \n",
+ " Sat Jun 20 12:56:51 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " taracollins086 | \n",
+ " Ate too much, feel sick | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 19995 | \n",
+ " 4 | \n",
+ " 2051447103 | \n",
+ " Fri Jun 05 22:02:36 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " _Jaska | \n",
+ " @girlwonder24 Thanks. | \n",
+ "
\n",
+ " \n",
+ " | 19996 | \n",
+ " 0 | \n",
+ " 2245469948 | \n",
+ " Fri Jun 19 16:10:39 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " julianicolao | \n",
+ " trying to study for the biggest test, next wee... | \n",
+ "
\n",
+ " \n",
+ " | 19997 | \n",
+ " 4 | \n",
+ " 2063022808 | \n",
+ " Sun Jun 07 01:05:46 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " ElaineToni | \n",
+ " Just finished watching Your Song Presents: Boy... | \n",
+ "
\n",
+ " \n",
+ " | 19998 | \n",
+ " 4 | \n",
+ " 1982082859 | \n",
+ " Sun May 31 10:29:36 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " lindseyrd20 | \n",
+ " @janfran813 awww i can't wait to get one | \n",
+ "
\n",
+ " \n",
+ " | 19999 | \n",
+ " 0 | \n",
+ " 2191411932 | \n",
+ " Tue Jun 16 05:13:13 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " serraannisa | \n",
+ " doing nothing | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
20000 rows × 6 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " target id date flag \\\n",
+ "0 0 2200003313 Tue Jun 16 18:18:13 PDT 2009 NO_QUERY \n",
+ "1 0 1467998601 Mon Apr 06 23:11:18 PDT 2009 NO_QUERY \n",
+ "2 0 2300049112 Tue Jun 23 13:40:12 PDT 2009 NO_QUERY \n",
+ "3 0 1993474319 Mon Jun 01 10:26:09 PDT 2009 NO_QUERY \n",
+ "4 0 2256551006 Sat Jun 20 12:56:51 PDT 2009 NO_QUERY \n",
+ "... ... ... ... ... \n",
+ "19995 4 2051447103 Fri Jun 05 22:02:36 PDT 2009 NO_QUERY \n",
+ "19996 0 2245469948 Fri Jun 19 16:10:39 PDT 2009 NO_QUERY \n",
+ "19997 4 2063022808 Sun Jun 07 01:05:46 PDT 2009 NO_QUERY \n",
+ "19998 4 1982082859 Sun May 31 10:29:36 PDT 2009 NO_QUERY \n",
+ "19999 0 2191411932 Tue Jun 16 05:13:13 PDT 2009 NO_QUERY \n",
+ "\n",
+ " user text \n",
+ "0 DEWGetMeTho77 @Nkluvr4eva My poor little dumpling In Holmde... \n",
+ "1 Young_J I'm off too bed. I gotta wake up hella early t... \n",
+ "2 dougnawoschik I havent been able to listen to it yet My spe... \n",
+ "3 thireven now remembers why solving a relatively big equ... \n",
+ "4 taracollins086 Ate too much, feel sick \n",
+ "... ... ... \n",
+ "19995 _Jaska @girlwonder24 Thanks. \n",
+ "19996 julianicolao trying to study for the biggest test, next wee... \n",
+ "19997 ElaineToni Just finished watching Your Song Presents: Boy... \n",
+ "19998 lindseyrd20 @janfran813 awww i can't wait to get one \n",
+ "19999 serraannisa doing nothing \n",
+ "\n",
+ "[20000 rows x 6 columns]"
+ ]
+ },
+ "execution_count": 29,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# subset of the data\n",
+ "\n",
+ "sample_size = 20000 # Number of records to sample\n",
+ "\n",
+ "sample_df = df.sample(n=sample_size, random_state=42)\n",
+ "sample_df=sample_df.reset_index(drop=True)\n",
+ "sample_df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Prepare Textual Data for Sentiment Analysis\n",
+ "\n",
+ "Now, apply the functions you have written in Challenge 1 to your whole data set. These functions include:\n",
+ "\n",
+ "* `clean_up()`\n",
+ "\n",
+ "* `tokenize()`\n",
+ "\n",
+ "* `stem_and_lemmatize()`\n",
+ "\n",
+ "* `remove_stopwords()`\n",
+ "\n",
+ "Create a new column called `text_processed` in the dataframe to contain the processed data. At the end, your `text_processed` column should contain lists of word tokens that are cleaned up. Your data should look like below:\n",
+ "\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " target | \n",
+ " id | \n",
+ " date | \n",
+ " flag | \n",
+ " user | \n",
+ " text | \n",
+ " text_processed | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 0 | \n",
+ " 2200003313 | \n",
+ " Tue Jun 16 18:18:13 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " DEWGetMeTho77 | \n",
+ " @Nkluvr4eva My poor little dumpling In Holmde... | \n",
+ " [nkluvr, eva, poor, little, dumpling, holmdel,... | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 0 | \n",
+ " 1467998601 | \n",
+ " Mon Apr 06 23:11:18 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " Young_J | \n",
+ " I'm off too bed. I gotta wake up hella early t... | \n",
+ " [bed, got, ta, wake, hella, early, tomorrow, m... | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 0 | \n",
+ " 2300049112 | \n",
+ " Tue Jun 23 13:40:12 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " dougnawoschik | \n",
+ " I havent been able to listen to it yet My spe... | \n",
+ " [havent, able, listen, yet, speaker, busted] | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 0 | \n",
+ " 1993474319 | \n",
+ " Mon Jun 01 10:26:09 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " thireven | \n",
+ " now remembers why solving a relatively big equ... | \n",
+ " [remembers, solving, relatively, big, equation... | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 0 | \n",
+ " 2256551006 | \n",
+ " Sat Jun 20 12:56:51 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " taracollins086 | \n",
+ " Ate too much, feel sick | \n",
+ " [ate, much, feel, sick] | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 19995 | \n",
+ " 4 | \n",
+ " 2051447103 | \n",
+ " Fri Jun 05 22:02:36 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " _Jaska | \n",
+ " @girlwonder24 Thanks. | \n",
+ " [girlwonder, thanks] | \n",
+ "
\n",
+ " \n",
+ " | 19996 | \n",
+ " 0 | \n",
+ " 2245469948 | \n",
+ " Fri Jun 19 16:10:39 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " julianicolao | \n",
+ " trying to study for the biggest test, next wee... | \n",
+ " [trying, study, biggest, test, next, week, wor... | \n",
+ "
\n",
+ " \n",
+ " | 19997 | \n",
+ " 4 | \n",
+ " 2063022808 | \n",
+ " Sun Jun 07 01:05:46 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " ElaineToni | \n",
+ " Just finished watching Your Song Presents: Boy... | \n",
+ " [finished, watching, song, present, boystown] | \n",
+ "
\n",
+ " \n",
+ " | 19998 | \n",
+ " 4 | \n",
+ " 1982082859 | \n",
+ " Sun May 31 10:29:36 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " lindseyrd20 | \n",
+ " @janfran813 awww i can't wait to get one | \n",
+ " [janfran, awww, wait, get, one] | \n",
+ "
\n",
+ " \n",
+ " | 19999 | \n",
+ " 0 | \n",
+ " 2191411932 | \n",
+ " Tue Jun 16 05:13:13 PDT 2009 | \n",
+ " NO_QUERY | \n",
+ " serraannisa | \n",
+ " doing nothing | \n",
+ " [nothing] | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
20000 rows × 7 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " target id date flag \\\n",
+ "0 0 2200003313 Tue Jun 16 18:18:13 PDT 2009 NO_QUERY \n",
+ "1 0 1467998601 Mon Apr 06 23:11:18 PDT 2009 NO_QUERY \n",
+ "2 0 2300049112 Tue Jun 23 13:40:12 PDT 2009 NO_QUERY \n",
+ "3 0 1993474319 Mon Jun 01 10:26:09 PDT 2009 NO_QUERY \n",
+ "4 0 2256551006 Sat Jun 20 12:56:51 PDT 2009 NO_QUERY \n",
+ "... ... ... ... ... \n",
+ "19995 4 2051447103 Fri Jun 05 22:02:36 PDT 2009 NO_QUERY \n",
+ "19996 0 2245469948 Fri Jun 19 16:10:39 PDT 2009 NO_QUERY \n",
+ "19997 4 2063022808 Sun Jun 07 01:05:46 PDT 2009 NO_QUERY \n",
+ "19998 4 1982082859 Sun May 31 10:29:36 PDT 2009 NO_QUERY \n",
+ "19999 0 2191411932 Tue Jun 16 05:13:13 PDT 2009 NO_QUERY \n",
+ "\n",
+ " user text \\\n",
+ "0 DEWGetMeTho77 @Nkluvr4eva My poor little dumpling In Holmde... \n",
+ "1 Young_J I'm off too bed. I gotta wake up hella early t... \n",
+ "2 dougnawoschik I havent been able to listen to it yet My spe... \n",
+ "3 thireven now remembers why solving a relatively big equ... \n",
+ "4 taracollins086 Ate too much, feel sick \n",
+ "... ... ... \n",
+ "19995 _Jaska @girlwonder24 Thanks. \n",
+ "19996 julianicolao trying to study for the biggest test, next wee... \n",
+ "19997 ElaineToni Just finished watching Your Song Presents: Boy... \n",
+ "19998 lindseyrd20 @janfran813 awww i can't wait to get one \n",
+ "19999 serraannisa doing nothing \n",
+ "\n",
+ " text_processed \n",
+ "0 [nkluvr, eva, poor, little, dumpling, holmdel,... \n",
+ "1 [bed, got, ta, wake, hella, early, tomorrow, m... \n",
+ "2 [havent, able, listen, yet, speaker, busted] \n",
+ "3 [remembers, solving, relatively, big, equation... \n",
+ "4 [ate, much, feel, sick] \n",
+ "... ... \n",
+ "19995 [girlwonder, thanks] \n",
+ "19996 [trying, study, biggest, test, next, week, wor... \n",
+ "19997 [finished, watching, song, present, boystown] \n",
+ "19998 [janfran, awww, wait, get, one] \n",
+ "19999 [nothing] \n",
+ "\n",
+ "[20000 rows x 7 columns]"
+ ]
+ },
+ "execution_count": 37,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# your code here\n",
+ "\n",
+ "df=sample_df\n",
+ "\n",
+ "def clean_up(s):\n",
+ " s = re.sub(r\"http\\S+|www\\S+|https\\S+\", \"\", s)\n",
+ " s = re.sub(r\"[^a-zA-Z]\", \" \", s)\n",
+ " s = s.lower()\n",
+ " return s\n",
+ "\n",
+ "def tokenize(s):\n",
+ " return word_tokenize(s)\n",
+ "\n",
+ "def lemmatize(l):\n",
+ " lemmatizer = WordNetLemmatizer()\n",
+ " return [lemmatizer.lemmatize(word) for word in l]\n",
+ "\n",
+ "def remove_stopwords(l):\n",
+ " stop_words = set(stopwords.words('english'))\n",
+ " return [word for word in l if word not in stop_words]\n",
+ "\n",
+ "df['text_processed'] = df['text'].apply(clean_up)\n",
+ "df['text_processed'] = df['text_processed'].apply(tokenize)\n",
+ "df['text_processed'] = df['text_processed'].apply(lemmatize)\n",
+ "df['text_processed'] = df['text_processed'].apply(remove_stopwords)\n",
+ "\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Creating Bag of Words\n",
+ "\n",
+ "The purpose of this step is to create a [bag of words](https://en.wikipedia.org/wiki/Bag-of-words_model) from the processed data. The bag of words contains all the unique words in your whole text body (a.k.a. *corpus*) with the number of occurrence of each word. It will allow you to understand which words are the most important features across the whole corpus.\n",
+ "\n",
+ "Also, you can imagine you will have a massive set of words. The less important words (i.e. those of very low number of occurrence) do not contribute much to the sentiment. Therefore, you only need to use the most important words to build your feature set in the next step. In our case, we will use the top 5,000 words with the highest frequency to build the features.\n",
+ "\n",
+ "In the cell below, combine all the words in `text_processed` and calculate the frequency distribution of all words. A convenient library to calculate the term frequency distribution is NLTK's `FreqDist` class ([documentation](https://www.nltk.org/api/nltk.html#module-nltk.probability)). Then select the top 5,000 words from the frequency distribution."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[('wa', 1400),\n",
+ " ('day', 1326),\n",
+ " ('good', 1175),\n",
+ " ('get', 1102),\n",
+ " ('like', 978),\n",
+ " ('go', 951),\n",
+ " ('quot', 921),\n",
+ " ('love', 904),\n",
+ " ('work', 867),\n",
+ " ('got', 847),\n",
+ " ('today', 829),\n",
+ " ('going', 799),\n",
+ " ('time', 789),\n",
+ " ('u', 784),\n",
+ " ('one', 747),\n",
+ " ('lol', 739),\n",
+ " ('know', 703),\n",
+ " ('im', 679),\n",
+ " ('back', 661),\n",
+ " ('really', 605),\n",
+ " ('want', 605),\n",
+ " ('night', 582),\n",
+ " ('well', 572),\n",
+ " ('amp', 568),\n",
+ " ('new', 567),\n",
+ " ('see', 564),\n",
+ " ('think', 556),\n",
+ " ('still', 547),\n",
+ " ('oh', 540),\n",
+ " ('thanks', 528),\n",
+ " ('na', 515),\n",
+ " ('ha', 512),\n",
+ " ('need', 507),\n",
+ " ('home', 506),\n",
+ " ('much', 480),\n",
+ " ('miss', 476),\n",
+ " ('feel', 462),\n",
+ " ('last', 446),\n",
+ " ('morning', 437),\n",
+ " ('great', 433),\n",
+ " ('make', 432),\n",
+ " ('tomorrow', 421),\n",
+ " ('twitter', 390),\n",
+ " ('haha', 379),\n",
+ " ('wish', 370),\n",
+ " ('hope', 366),\n",
+ " ('bad', 364),\n",
+ " ('sad', 359),\n",
+ " ('fun', 347),\n",
+ " ('come', 345),\n",
+ " ('sleep', 343),\n",
+ " ('would', 342),\n",
+ " ('nice', 330),\n",
+ " ('sorry', 328),\n",
+ " ('right', 326),\n",
+ " ('week', 325),\n",
+ " ('tonight', 322),\n",
+ " ('happy', 322),\n",
+ " ('say', 316),\n",
+ " ('thing', 312),\n",
+ " ('getting', 310),\n",
+ " ('look', 309),\n",
+ " ('friend', 307),\n",
+ " ('gon', 299),\n",
+ " ('though', 298),\n",
+ " ('hate', 293),\n",
+ " ('wait', 289),\n",
+ " ('better', 279),\n",
+ " ('bed', 278),\n",
+ " ('way', 277),\n",
+ " ('watching', 274),\n",
+ " ('lt', 267),\n",
+ " ('people', 264),\n",
+ " ('yeah', 263),\n",
+ " ('hour', 259),\n",
+ " ('show', 249),\n",
+ " ('could', 247),\n",
+ " ('thank', 242),\n",
+ " ('take', 241),\n",
+ " ('weekend', 240),\n",
+ " ('next', 239),\n",
+ " ('yes', 238),\n",
+ " ('school', 236),\n",
+ " ('even', 236),\n",
+ " ('little', 235),\n",
+ " ('life', 234),\n",
+ " ('working', 230),\n",
+ " ('guy', 226),\n",
+ " ('x', 226),\n",
+ " ('everyone', 225),\n",
+ " ('sick', 224),\n",
+ " ('cant', 224),\n",
+ " ('girl', 223),\n",
+ " ('dont', 222),\n",
+ " ('let', 220),\n",
+ " ('hey', 220),\n",
+ " ('awesome', 219),\n",
+ " ('movie', 215),\n",
+ " ('tweet', 212),\n",
+ " ('always', 211),\n",
+ " ('never', 210),\n",
+ " ('please', 210),\n",
+ " ('watch', 210),\n",
+ " ('soon', 209),\n",
+ " ('year', 207),\n",
+ " ('first', 203),\n",
+ " ('long', 202),\n",
+ " ('ok', 200),\n",
+ " ('tired', 198),\n",
+ " ('already', 197),\n",
+ " ('feeling', 195),\n",
+ " ('suck', 194),\n",
+ " ('wan', 193),\n",
+ " ('best', 186),\n",
+ " ('sure', 186),\n",
+ " ('looking', 185),\n",
+ " ('man', 183),\n",
+ " ('n', 182),\n",
+ " ('another', 180),\n",
+ " ('something', 179),\n",
+ " ('find', 178),\n",
+ " ('start', 178),\n",
+ " ('cool', 178),\n",
+ " ('done', 178),\n",
+ " ('pretty', 177),\n",
+ " ('omg', 175),\n",
+ " ('yay', 175),\n",
+ " ('yet', 173),\n",
+ " ('phone', 173),\n",
+ " ('damn', 172),\n",
+ " ('lot', 170),\n",
+ " ('away', 166),\n",
+ " ('went', 165),\n",
+ " ('old', 165),\n",
+ " ('follow', 164),\n",
+ " ('help', 163),\n",
+ " ('guess', 162),\n",
+ " ('song', 161),\n",
+ " ('keep', 160),\n",
+ " ('house', 160),\n",
+ " ('thought', 160),\n",
+ " ('sun', 159),\n",
+ " ('made', 159),\n",
+ " ('ever', 158),\n",
+ " ('trying', 157),\n",
+ " ('ya', 157),\n",
+ " ('bit', 154),\n",
+ " ('game', 153),\n",
+ " ('hurt', 153),\n",
+ " ('finally', 151),\n",
+ " ('maybe', 151),\n",
+ " ('big', 150),\n",
+ " ('sound', 150),\n",
+ " ('ready', 150),\n",
+ " ('lost', 147),\n",
+ " ('p', 146),\n",
+ " ('nothing', 146),\n",
+ " ('someone', 145),\n",
+ " ('early', 144),\n",
+ " ('summer', 144),\n",
+ " ('tell', 141),\n",
+ " ('b', 141),\n",
+ " ('hard', 140),\n",
+ " ('also', 140),\n",
+ " ('birthday', 140),\n",
+ " ('w', 140),\n",
+ " ('th', 139),\n",
+ " ('left', 138),\n",
+ " ('mean', 138),\n",
+ " ('rain', 137),\n",
+ " ('missed', 137),\n",
+ " ('ur', 137),\n",
+ " ('r', 136),\n",
+ " ('pic', 136),\n",
+ " ('mom', 135),\n",
+ " ('baby', 135),\n",
+ " ('wow', 133),\n",
+ " ('party', 133),\n",
+ " ('two', 132),\n",
+ " ('glad', 132),\n",
+ " ('world', 132),\n",
+ " ('might', 130),\n",
+ " ('bored', 128),\n",
+ " ('call', 128),\n",
+ " ('ta', 126),\n",
+ " ('check', 126),\n",
+ " ('late', 126),\n",
+ " ('waiting', 126),\n",
+ " ('car', 126),\n",
+ " ('video', 124),\n",
+ " ('stuff', 124),\n",
+ " ('found', 124),\n",
+ " ('yesterday', 124),\n",
+ " ('hot', 123),\n",
+ " ('weather', 123),\n",
+ " ('said', 123),\n",
+ " ('sunday', 123),\n",
+ " ('live', 123),\n",
+ " ('luck', 123),\n",
+ " ('saw', 123),\n",
+ " ('amazing', 123),\n",
+ " ('monday', 122),\n",
+ " ('many', 122),\n",
+ " ('doe', 121),\n",
+ " ('exam', 121),\n",
+ " ('thats', 121),\n",
+ " ('iphone', 121),\n",
+ " ('may', 120),\n",
+ " ('play', 119),\n",
+ " ('making', 119),\n",
+ " ('boy', 118),\n",
+ " ('excited', 118),\n",
+ " ('god', 117),\n",
+ " ('dad', 117),\n",
+ " ('family', 116),\n",
+ " ('gone', 116),\n",
+ " ('friday', 115),\n",
+ " ('follower', 114),\n",
+ " ('read', 114),\n",
+ " ('funny', 113),\n",
+ " ('give', 113),\n",
+ " ('poor', 112),\n",
+ " ('hi', 112),\n",
+ " ('since', 112),\n",
+ " ('enjoy', 111),\n",
+ " ('job', 111),\n",
+ " ('talk', 109),\n",
+ " ('okay', 109),\n",
+ " ('later', 108),\n",
+ " ('head', 107),\n",
+ " ('beautiful', 107),\n",
+ " ('almost', 106),\n",
+ " ('woke', 106),\n",
+ " ('gt', 106),\n",
+ " ('cold', 106),\n",
+ " ('free', 105),\n",
+ " ('anything', 105),\n",
+ " ('hear', 105),\n",
+ " ('lunch', 104),\n",
+ " ('missing', 104),\n",
+ " ('put', 104),\n",
+ " ('try', 103),\n",
+ " ('coming', 103),\n",
+ " ('must', 102),\n",
+ " ('end', 101),\n",
+ " ('tho', 100),\n",
+ " ('leave', 100),\n",
+ " ('ugh', 99),\n",
+ " ('music', 99),\n",
+ " ('food', 99),\n",
+ " ('till', 99),\n",
+ " ('book', 98),\n",
+ " ('busy', 98),\n",
+ " ('around', 98),\n",
+ " ('far', 98),\n",
+ " ('cry', 97),\n",
+ " ('headache', 97),\n",
+ " ('cause', 97),\n",
+ " ('fan', 97),\n",
+ " ('xx', 96),\n",
+ " ('use', 96),\n",
+ " ('listening', 96),\n",
+ " ('stop', 96),\n",
+ " ('stay', 95),\n",
+ " ('totally', 95),\n",
+ " ('wanted', 95),\n",
+ " ('place', 95),\n",
+ " ('shit', 95),\n",
+ " ('least', 94),\n",
+ " ('sweet', 94),\n",
+ " ('picture', 94),\n",
+ " ('update', 94),\n",
+ " ('anyone', 93),\n",
+ " ('lovely', 92),\n",
+ " ('thinking', 92),\n",
+ " ('forward', 92),\n",
+ " ('aww', 92),\n",
+ " ('dog', 92),\n",
+ " ('tv', 91),\n",
+ " ('class', 90),\n",
+ " ('actually', 90),\n",
+ " ('everything', 90),\n",
+ " ('eat', 89),\n",
+ " ('mine', 89),\n",
+ " ('playing', 89),\n",
+ " ('cute', 89),\n",
+ " ('hahaha', 87),\n",
+ " ('kid', 87),\n",
+ " ('dinner', 87),\n",
+ " ('e', 86),\n",
+ " ('stupid', 86),\n",
+ " ('sooo', 86),\n",
+ " ('win', 86),\n",
+ " ('came', 86),\n",
+ " ('word', 85),\n",
+ " ('ill', 85),\n",
+ " ('eating', 85),\n",
+ " ('hopefully', 84),\n",
+ " ('finished', 84),\n",
+ " ('welcome', 84),\n",
+ " ('anymore', 83),\n",
+ " ('minute', 82),\n",
+ " ('every', 82),\n",
+ " ('face', 82),\n",
+ " ('idea', 81),\n",
+ " ('hair', 81),\n",
+ " ('super', 80),\n",
+ " ('without', 80),\n",
+ " ('kinda', 80),\n",
+ " ('month', 79),\n",
+ " ('saturday', 79),\n",
+ " ('wrong', 79),\n",
+ " ('final', 78),\n",
+ " ('true', 78),\n",
+ " ('reading', 78),\n",
+ " ('hug', 78),\n",
+ " ('probably', 78),\n",
+ " ('photo', 77),\n",
+ " ('name', 77),\n",
+ " ('buy', 77),\n",
+ " ('hehe', 77),\n",
+ " ('taking', 77),\n",
+ " ('believe', 77),\n",
+ " ('eye', 77),\n",
+ " ('didnt', 76),\n",
+ " ('g', 76),\n",
+ " ('alone', 76),\n",
+ " ('boo', 76),\n",
+ " ('mind', 75),\n",
+ " ('real', 75),\n",
+ " ('room', 75),\n",
+ " ('c', 75),\n",
+ " ('either', 75),\n",
+ " ('dream', 75),\n",
+ " ('following', 75),\n",
+ " ('able', 74),\n",
+ " ('goodnight', 74),\n",
+ " ('mileycyrus', 74),\n",
+ " ('else', 74),\n",
+ " ('lmao', 74),\n",
+ " ('heard', 73),\n",
+ " ('part', 73),\n",
+ " ('coffee', 73),\n",
+ " ('outside', 73),\n",
+ " ('blog', 73),\n",
+ " ('break', 73),\n",
+ " ('june', 72),\n",
+ " ('computer', 72),\n",
+ " ('forgot', 72),\n",
+ " ('ticket', 72),\n",
+ " ('post', 72),\n",
+ " ('rest', 71),\n",
+ " ('dude', 71),\n",
+ " ('half', 71),\n",
+ " ('pm', 71),\n",
+ " ('enough', 71),\n",
+ " ('brother', 71),\n",
+ " ('plan', 71),\n",
+ " ('rock', 70),\n",
+ " ('using', 70),\n",
+ " ('add', 70),\n",
+ " ('stuck', 70),\n",
+ " ('person', 70),\n",
+ " ('text', 70),\n",
+ " ('meet', 69),\n",
+ " ('mother', 69),\n",
+ " ('album', 69),\n",
+ " ('study', 69),\n",
+ " ('crazy', 69),\n",
+ " ('hand', 69),\n",
+ " ('send', 69),\n",
+ " ('fine', 68),\n",
+ " ('talking', 68),\n",
+ " ('whole', 68),\n",
+ " ('reply', 68),\n",
+ " ('nite', 68),\n",
+ " ('seems', 67),\n",
+ " ('run', 67),\n",
+ " ('red', 66),\n",
+ " ('took', 66),\n",
+ " ('hello', 66),\n",
+ " ('seen', 66),\n",
+ " ('trip', 65),\n",
+ " ('full', 65),\n",
+ " ('beach', 65),\n",
+ " ('hit', 65),\n",
+ " ('side', 64),\n",
+ " ('loved', 64),\n",
+ " ('news', 64),\n",
+ " ('change', 64),\n",
+ " ('heart', 64),\n",
+ " ('la', 64),\n",
+ " ('tried', 63),\n",
+ " ('kind', 63),\n",
+ " ('star', 63),\n",
+ " ('yea', 63),\n",
+ " ('shopping', 63),\n",
+ " ('problem', 63),\n",
+ " ('afternoon', 63),\n",
+ " ('pain', 62),\n",
+ " ('nap', 62),\n",
+ " ('started', 62),\n",
+ " ('used', 62),\n",
+ " ('k', 61),\n",
+ " ('remember', 61),\n",
+ " ('boring', 61),\n",
+ " ('course', 61),\n",
+ " ('heading', 61),\n",
+ " ('quite', 60),\n",
+ " ('seeing', 60),\n",
+ " ('hell', 60),\n",
+ " ('train', 60),\n",
+ " ('breakfast', 60),\n",
+ " ('til', 60),\n",
+ " ('crap', 60),\n",
+ " ('told', 60),\n",
+ " ('english', 60),\n",
+ " ('died', 60),\n",
+ " ('sister', 60),\n",
+ " ('fuck', 60),\n",
+ " ('site', 60),\n",
+ " ('instead', 60),\n",
+ " ('leaving', 59),\n",
+ " ('ipod', 59),\n",
+ " ('money', 59),\n",
+ " ('raining', 59),\n",
+ " ('finish', 59),\n",
+ " ('cat', 59),\n",
+ " ('com', 59),\n",
+ " ('anyway', 59),\n",
+ " ('ah', 58),\n",
+ " ('running', 58),\n",
+ " ('concert', 58),\n",
+ " ('soo', 58),\n",
+ " ('facebook', 58),\n",
+ " ('link', 58),\n",
+ " ('sitting', 57),\n",
+ " ('point', 57),\n",
+ " ('jealous', 57),\n",
+ " ('l', 57),\n",
+ " ('season', 57),\n",
+ " ('bring', 57),\n",
+ " ('cuz', 57),\n",
+ " ('awake', 56),\n",
+ " ('reason', 56),\n",
+ " ('studying', 56),\n",
+ " ('xd', 56),\n",
+ " ('pay', 56),\n",
+ " ('wonder', 56),\n",
+ " ('lucky', 56),\n",
+ " ('congrats', 55),\n",
+ " ('ago', 55),\n",
+ " ('mum', 55),\n",
+ " ('page', 55),\n",
+ " ('bought', 55),\n",
+ " ('store', 55),\n",
+ " ('drink', 55),\n",
+ " ('definitely', 55),\n",
+ " ('v', 55),\n",
+ " ('couple', 54),\n",
+ " ('evening', 54),\n",
+ " ('chocolate', 54),\n",
+ " ('btw', 54),\n",
+ " ('soooo', 54),\n",
+ " ('sunny', 54),\n",
+ " ('sore', 54),\n",
+ " ('drive', 54),\n",
+ " ('shower', 54),\n",
+ " ('test', 53),\n",
+ " ('walk', 53),\n",
+ " ('internet', 53),\n",
+ " ('st', 53),\n",
+ " ('open', 53),\n",
+ " ('water', 53),\n",
+ " ('wake', 52),\n",
+ " ('aw', 52),\n",
+ " ('smile', 52),\n",
+ " ('office', 52),\n",
+ " ('list', 52),\n",
+ " ('watched', 52),\n",
+ " ('team', 52),\n",
+ " ('tommcfly', 52),\n",
+ " ('clean', 51),\n",
+ " ('enjoying', 51),\n",
+ " ('hungry', 51),\n",
+ " ('seriously', 50),\n",
+ " ('move', 50),\n",
+ " ('wont', 50),\n",
+ " ('high', 50),\n",
+ " ('asleep', 50),\n",
+ " ('award', 50),\n",
+ " ('fucking', 50),\n",
+ " ('dance', 50),\n",
+ " ('bout', 50),\n",
+ " ('project', 50),\n",
+ " ('second', 50),\n",
+ " ('starting', 50),\n",
+ " ('le', 50),\n",
+ " ('top', 50),\n",
+ " ('moment', 49),\n",
+ " ('loving', 49),\n",
+ " ('park', 48),\n",
+ " ('ask', 48),\n",
+ " ('email', 48),\n",
+ " ('mr', 48),\n",
+ " ('church', 48),\n",
+ " ('driving', 48),\n",
+ " ('tea', 48),\n",
+ " ('broke', 48),\n",
+ " ('gym', 48),\n",
+ " ('ride', 48),\n",
+ " ('awww', 48),\n",
+ " ('black', 48),\n",
+ " ('meeting', 47),\n",
+ " ('hr', 47),\n",
+ " ('worth', 47),\n",
+ " ('fail', 47),\n",
+ " ('close', 47),\n",
+ " ('visit', 47),\n",
+ " ('sigh', 47),\n",
+ " ('ate', 46),\n",
+ " ('online', 46),\n",
+ " ('number', 46),\n",
+ " ('vote', 46),\n",
+ " ('lady', 46),\n",
+ " ('bye', 46),\n",
+ " ('hang', 46),\n",
+ " ('wonderful', 46),\n",
+ " ('youtube', 46),\n",
+ " ('care', 46),\n",
+ " ('cut', 45),\n",
+ " ('drinking', 45),\n",
+ " ('horrible', 45),\n",
+ " ('ddlovato', 45),\n",
+ " ('shirt', 45),\n",
+ " ('f', 45),\n",
+ " ('da', 45),\n",
+ " ('ice', 45),\n",
+ " ('saying', 45),\n",
+ " ('answer', 45),\n",
+ " ('date', 44),\n",
+ " ('dear', 44),\n",
+ " ('agree', 44),\n",
+ " ('set', 44),\n",
+ " ('town', 44),\n",
+ " ('co', 44),\n",
+ " ('wear', 44),\n",
+ " ('happened', 44),\n",
+ " ('line', 44),\n",
+ " ('parent', 44),\n",
+ " ('worse', 43),\n",
+ " ('min', 43),\n",
+ " ('longer', 43),\n",
+ " ('j', 43),\n",
+ " ('together', 43),\n",
+ " ('cream', 43),\n",
+ " ('worry', 43),\n",
+ " ('goin', 43),\n",
+ " ('followfriday', 43),\n",
+ " ('fast', 42),\n",
+ " ('forget', 42),\n",
+ " ('fb', 42),\n",
+ " ('doesnt', 42),\n",
+ " ('sometimes', 42),\n",
+ " ('broken', 42),\n",
+ " ('wtf', 42),\n",
+ " ('turn', 42),\n",
+ " ('unfortunately', 42),\n",
+ " ('chance', 42),\n",
+ " ('favorite', 41),\n",
+ " ('spent', 41),\n",
+ " ('fall', 41),\n",
+ " ('air', 41),\n",
+ " ('idk', 41),\n",
+ " ('slept', 41),\n",
+ " ('rainy', 41),\n",
+ " ('question', 41),\n",
+ " ('laptop', 41),\n",
+ " ('holiday', 41),\n",
+ " ('tweeting', 41),\n",
+ " ('tuesday', 41),\n",
+ " ('earlier', 41),\n",
+ " ('mood', 41),\n",
+ " ('slow', 41),\n",
+ " ('hoping', 41),\n",
+ " ('thx', 41),\n",
+ " ('absolutely', 40),\n",
+ " ('ahh', 40),\n",
+ " ('city', 40),\n",
+ " ('cleaning', 40),\n",
+ " ('via', 40),\n",
+ " ('happen', 40),\n",
+ " ('wishing', 40),\n",
+ " ('taken', 40),\n",
+ " ('pool', 40),\n",
+ " ('episode', 40),\n",
+ " ('garden', 39),\n",
+ " ('homework', 39),\n",
+ " ('website', 39),\n",
+ " ('sleeping', 39),\n",
+ " ('airport', 39),\n",
+ " ('especially', 39),\n",
+ " ('mac', 39),\n",
+ " ('business', 38),\n",
+ " ('perfect', 38),\n",
+ " ('fell', 38),\n",
+ " ('upset', 38),\n",
+ " ('story', 38),\n",
+ " ('small', 38),\n",
+ " ('chat', 38),\n",
+ " ('knew', 38),\n",
+ " ('shop', 38),\n",
+ " ('foot', 38),\n",
+ " ('chicken', 38),\n",
+ " ('father', 38),\n",
+ " ('throat', 38),\n",
+ " ('weird', 38),\n",
+ " ('window', 38),\n",
+ " ('woman', 37),\n",
+ " ('em', 37),\n",
+ " ('passed', 37),\n",
+ " ('son', 37),\n",
+ " ('nd', 37),\n",
+ " ('tour', 37),\n",
+ " ('message', 37),\n",
+ " ('green', 37),\n",
+ " ('wednesday', 37),\n",
+ " ('gave', 37),\n",
+ " ('due', 37),\n",
+ " ('bbq', 37),\n",
+ " ('h', 37),\n",
+ " ('listen', 36),\n",
+ " ('sleepy', 36),\n",
+ " ('white', 36),\n",
+ " ('tom', 36),\n",
+ " ('company', 36),\n",
+ " ('sunshine', 36),\n",
+ " ('met', 36),\n",
+ " ('short', 36),\n",
+ " ('comment', 36),\n",
+ " ('mad', 36),\n",
+ " ('understand', 36),\n",
+ " ('pc', 36),\n",
+ " ('dead', 36),\n",
+ " ('hubby', 36),\n",
+ " ('power', 36),\n",
+ " ('different', 36),\n",
+ " ('havent', 35),\n",
+ " ('account', 35),\n",
+ " ('note', 35),\n",
+ " ('support', 35),\n",
+ " ('seem', 35),\n",
+ " ('scared', 35),\n",
+ " ('bag', 35),\n",
+ " ('alright', 35),\n",
+ " ('hangover', 35),\n",
+ " ('touch', 35),\n",
+ " ('cup', 35),\n",
+ " ('ive', 35),\n",
+ " ('leg', 35),\n",
+ " ('interesting', 35),\n",
+ " ('bus', 35),\n",
+ " ('past', 35),\n",
+ " ('glass', 35),\n",
+ " ('worst', 35),\n",
+ " ('plz', 35),\n",
+ " ('math', 35),\n",
+ " ('bitch', 35),\n",
+ " ('nope', 34),\n",
+ " ('david', 34),\n",
+ " ('sat', 34),\n",
+ " ('moon', 34),\n",
+ " ('si', 34),\n",
+ " ('taylor', 34),\n",
+ " ('xoxo', 34),\n",
+ " ('order', 34),\n",
+ " ('jonas', 34),\n",
+ " ('pick', 34),\n",
+ " ('forever', 34),\n",
+ " ('uk', 34),\n",
+ " ('kill', 34),\n",
+ " ('shoot', 34),\n",
+ " ('called', 34),\n",
+ " ('rather', 34),\n",
+ " ('catch', 34),\n",
+ " ('bet', 33),\n",
+ " ('officially', 33),\n",
+ " ('vip', 33),\n",
+ " ('writing', 33),\n",
+ " ('moving', 33),\n",
+ " ('lil', 33),\n",
+ " ('worried', 33),\n",
+ " ('write', 33),\n",
+ " ('special', 33),\n",
+ " ('graduation', 33),\n",
+ " ('liked', 33),\n",
+ " ('except', 33),\n",
+ " ('bday', 33),\n",
+ " ('gay', 32),\n",
+ " ('dang', 32),\n",
+ " ('box', 32),\n",
+ " ('cousin', 32),\n",
+ " ('load', 32),\n",
+ " ('sent', 32),\n",
+ " ('fix', 32),\n",
+ " ('random', 32),\n",
+ " ('ahhh', 32),\n",
+ " ('club', 32),\n",
+ " ('fly', 32),\n",
+ " ('blue', 32),\n",
+ " ('college', 32),\n",
+ " ('gorgeous', 32),\n",
+ " ('apple', 32),\n",
+ " ('interview', 32),\n",
+ " ('fight', 32),\n",
+ " ('everybody', 32),\n",
+ " ('dress', 31),\n",
+ " ('bro', 31),\n",
+ " ('case', 31),\n",
+ " ('july', 31),\n",
+ " ('cake', 31),\n",
+ " ('three', 31),\n",
+ " ('hmm', 31),\n",
+ " ('deal', 31),\n",
+ " ('ouch', 31),\n",
+ " ('living', 31),\n",
+ " ('inside', 31),\n",
+ " ('yep', 31),\n",
+ " ('meant', 31),\n",
+ " ('profile', 31),\n",
+ " ('mtv', 31),\n",
+ " ('wedding', 31),\n",
+ " ('clothes', 31),\n",
+ " ('band', 31),\n",
+ " ('issue', 31),\n",
+ " ('apparently', 31),\n",
+ " ('lonely', 31),\n",
+ " ('age', 31),\n",
+ " ('shall', 31),\n",
+ " ('flight', 31),\n",
+ " ('yr', 30),\n",
+ " ('supposed', 30),\n",
+ " ('needed', 30),\n",
+ " ('bloody', 30),\n",
+ " ('london', 30),\n",
+ " ('laugh', 30),\n",
+ " ('sign', 30),\n",
+ " ('finger', 30),\n",
+ " ('beer', 30),\n",
+ " ('itunes', 30),\n",
+ " ('played', 30),\n",
+ " ('tear', 30),\n",
+ " ('ppl', 30),\n",
+ " ('shoe', 29),\n",
+ " ('body', 29),\n",
+ " ('paper', 29),\n",
+ " ('group', 29),\n",
+ " ('looked', 29),\n",
+ " ('sadly', 29),\n",
+ " ('mark', 29),\n",
+ " ('vacation', 29),\n",
+ " ('myspace', 29),\n",
+ " ('jonasbrothers', 29),\n",
+ " ('version', 29),\n",
+ " ('huge', 29),\n",
+ " ('sooooo', 29),\n",
+ " ('lakers', 29),\n",
+ " ('germany', 29),\n",
+ " ('save', 29),\n",
+ " ('hanging', 29),\n",
+ " ('fantastic', 28),\n",
+ " ('camera', 28),\n",
+ " ('wine', 28),\n",
+ " ('web', 28),\n",
+ " ('sort', 28),\n",
+ " ('none', 28),\n",
+ " ('twilight', 28),\n",
+ " ('shot', 28),\n",
+ " ('thursday', 28),\n",
+ " ('confused', 28),\n",
+ " ('sale', 28),\n",
+ " ('goodbye', 28),\n",
+ " ('round', 28),\n",
+ " ('lame', 28),\n",
+ " ('cheer', 28),\n",
+ " ('singing', 28),\n",
+ " ('promise', 28),\n",
+ " ('drop', 28),\n",
+ " ('nose', 28),\n",
+ " ('whats', 28),\n",
+ " ('babe', 28),\n",
+ " ('xxx', 27),\n",
+ " ('radio', 27),\n",
+ " ('lesson', 27),\n",
+ " ('download', 27),\n",
+ " ('fact', 27),\n",
+ " ('info', 27),\n",
+ " ('fair', 27),\n",
+ " ('yummy', 27),\n",
+ " ('kitty', 27),\n",
+ " ('french', 27),\n",
+ " ('miley', 27),\n",
+ " ('light', 27),\n",
+ " ('asked', 27),\n",
+ " ('lazy', 27),\n",
+ " ('indeed', 27),\n",
+ " ('along', 27),\n",
+ " ('quick', 27),\n",
+ " ('door', 27),\n",
+ " ('sit', 27),\n",
+ " ('yup', 27),\n",
+ " ('street', 27),\n",
+ " ('mile', 27),\n",
+ " ('dm', 27),\n",
+ " ('puppy', 27),\n",
+ " ('jus', 27),\n",
+ " ('giving', 27),\n",
+ " ('ear', 27),\n",
+ " ('service', 27),\n",
+ " ('low', 26),\n",
+ " ('relaxing', 26),\n",
+ " ('arm', 26),\n",
+ " ('future', 26),\n",
+ " ('proud', 26),\n",
+ " ('learn', 26),\n",
+ " ('easy', 26),\n",
+ " ('child', 26),\n",
+ " ('hold', 26),\n",
+ " ('peep', 26),\n",
+ " ('yo', 26),\n",
+ " ('wearing', 26),\n",
+ " ('luv', 26),\n",
+ " ('south', 26),\n",
+ " ('road', 26),\n",
+ " ('smell', 26),\n",
+ " ('beat', 26),\n",
+ " ('pink', 26),\n",
+ " ('exciting', 26),\n",
+ " ('currently', 26),\n",
+ " ('warm', 26),\n",
+ " ('snow', 26),\n",
+ " ('packing', 26),\n",
+ " ('google', 26),\n",
+ " ('nobody', 26),\n",
+ " ('exactly', 26),\n",
+ " ('share', 26),\n",
+ " ('decided', 26),\n",
+ " ('voice', 26),\n",
+ " ('fat', 26),\n",
+ " ('mommy', 26),\n",
+ " ('realize', 26),\n",
+ " ('join', 26),\n",
+ " ('nearly', 25),\n",
+ " ('bb', 25),\n",
+ " ('whatever', 25),\n",
+ " ('woo', 25),\n",
+ " ('spend', 25),\n",
+ " ('stand', 25),\n",
+ " ('enjoyed', 25),\n",
+ " ('tweeps', 25),\n",
+ " ('sold', 25),\n",
+ " ('gettin', 25),\n",
+ " ('fever', 25),\n",
+ " ('paid', 25),\n",
+ " ('joe', 25),\n",
+ " ('mall', 25),\n",
+ " ('hill', 25),\n",
+ " ('gunna', 25),\n",
+ " ('freaking', 25),\n",
+ " ('hospital', 25),\n",
+ " ('cheese', 25),\n",
+ " ('wondering', 25),\n",
+ " ('plane', 25),\n",
+ " ('shame', 25),\n",
+ " ('tan', 25),\n",
+ " ('ended', 24),\n",
+ " ('helping', 24),\n",
+ " ('safe', 24),\n",
+ " ('staying', 24),\n",
+ " ('young', 24),\n",
+ " ('honey', 24),\n",
+ " ('storm', 24),\n",
+ " ('fam', 24),\n",
+ " ('art', 24),\n",
+ " ('bird', 24),\n",
+ " ('sing', 24),\n",
+ " ('card', 24),\n",
+ " ('stick', 24),\n",
+ " ('matter', 24),\n",
+ " ('delicious', 24),\n",
+ " ('cook', 24),\n",
+ " ('country', 24),\n",
+ " ('peace', 24),\n",
+ " ('worked', 24),\n",
+ " ('race', 24),\n",
+ " ('boot', 24),\n",
+ " ('figure', 24),\n",
+ " ('vega', 24),\n",
+ " ('france', 24),\n",
+ " ('wit', 24),\n",
+ " ('mcfly', 24),\n",
+ " ('chris', 24),\n",
+ " ('topic', 24),\n",
+ " ('film', 24),\n",
+ " ('spot', 24),\n",
+ " ('cover', 24),\n",
+ " ('afford', 24),\n",
+ " ('search', 24),\n",
+ " ('floor', 23),\n",
+ " ('bike', 23),\n",
+ " ('starbucks', 23),\n",
+ " ('rob', 23),\n",
+ " ('hahah', 23),\n",
+ " ('tummy', 23),\n",
+ " ('trouble', 23),\n",
+ " ('mouth', 23),\n",
+ " ('ran', 23),\n",
+ " ('drunk', 23),\n",
+ " ('lately', 23),\n",
+ " ('joke', 23),\n",
+ " ('flu', 23),\n",
+ " ('view', 23),\n",
+ " ('showing', 23),\n",
+ " ('mail', 23),\n",
+ " ('turned', 23),\n",
+ " ('men', 23),\n",
+ " ('taste', 23),\n",
+ " ('gosh', 23),\n",
+ " ('bar', 23),\n",
+ " ('changed', 23),\n",
+ " ('fish', 23),\n",
+ " ('stopped', 23),\n",
+ " ('wife', 23),\n",
+ " ('alot', 23),\n",
+ " ('tweetdeck', 23),\n",
+ " ('magic', 23),\n",
+ " ('brilliant', 23),\n",
+ " ('cooking', 23),\n",
+ " ('state', 23),\n",
+ " ('design', 23),\n",
+ " ('isnt', 23),\n",
+ " ('nail', 23),\n",
+ " ('bummed', 22),\n",
+ " ('prob', 22),\n",
+ " ('happens', 22),\n",
+ " ('eh', 22),\n",
+ " ('type', 22),\n",
+ " ('secret', 22),\n",
+ " ('alex', 22),\n",
+ " ('price', 22),\n",
+ " ('disappointed', 22),\n",
+ " ('angel', 22),\n",
+ " ('xo', 22),\n",
+ " ('sky', 22),\n",
+ " ('ring', 22),\n",
+ " ('surprise', 22),\n",
+ " ('self', 22),\n",
+ " ('depressing', 22),\n",
+ " ('sexy', 22),\n",
+ " ('woot', 22),\n",
+ " ('pop', 22),\n",
+ " ('piece', 22),\n",
+ " ('ooh', 22),\n",
+ " ('degree', 22),\n",
+ " ('chillin', 22),\n",
+ " ('hilarious', 22),\n",
+ " ('rip', 22),\n",
+ " ('updated', 22),\n",
+ " ('ohh', 22),\n",
+ " ('block', 22),\n",
+ " ('boyfriend', 22),\n",
+ " ('hun', 22),\n",
+ " ('crappy', 22),\n",
+ " ('er', 22),\n",
+ " ('although', 22),\n",
+ " ('death', 22),\n",
+ " ('lake', 22),\n",
+ " ('nick', 22),\n",
+ " ('ahead', 22),\n",
+ " ('watchin', 22),\n",
+ " ('daddy', 22),\n",
+ " ('scary', 22),\n",
+ " ('annoying', 22),\n",
+ " ('event', 22),\n",
+ " ('plus', 22),\n",
+ " ('ff', 22),\n",
+ " ('bill', 22),\n",
+ " ('major', 22),\n",
+ " ('afraid', 21),\n",
+ " ('pissed', 21),\n",
+ " ('wat', 21),\n",
+ " ('huh', 21),\n",
+ " ('others', 21),\n",
+ " ('land', 21),\n",
+ " ('caught', 21),\n",
+ " ('closed', 21),\n",
+ " ('kiss', 21),\n",
+ " ('trek', 21),\n",
+ " ('cd', 21),\n",
+ " ('code', 21),\n",
+ " ...]"
+ ]
+ },
+ "execution_count": 41,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "all_words = [word for sublist in df['text_processed'] for word in sublist]\n",
+ "\n",
+ "freq_dist = FreqDist(all_words)\n",
+ "\n",
+ "top_words = freq_dist.most_common(5000)\n",
+ "top_words"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Building Features\n",
+ "\n",
+ "Now let's build the features. Using the top 5,000 words, create a 2-dimensional matrix to record whether each of those words is contained in each document (tweet). Then you also have an output column to indicate whether the sentiment in each tweet is positive. For example, assuming your bag of words has 5 items (`['one', 'two', 'three', 'four', 'five']`) out of 4 documents (`['A', 'B', 'C', 'D']`), your feature set is essentially:\n",
+ "\n",
+ "| Doc | one | two | three | four | five | is_positive |\n",
+ "|---|---|---|---|---|---|---|\n",
+ "| A | True | False | False | True | False | True |\n",
+ "| B | False | False | False | True | True | False |\n",
+ "| C | False | True | False | False | False | True |\n",
+ "| D | True | False | False | False | True | False|\n",
+ "\n",
+ "However, because the `nltk.NaiveBayesClassifier.train` class we will use in the next step does not work with Pandas dataframe, the structure of your feature set should be converted to the Python list looking like below:\n",
+ "\n",
+ "```python\n",
+ "[\n",
+ "\t({\n",
+ "\t\t'one': True,\n",
+ "\t\t'two': False,\n",
+ "\t\t'three': False,\n",
+ "\t\t'four': True,\n",
+ "\t\t'five': False\n",
+ "\t}, True),\n",
+ "\t({\n",
+ "\t\t'one': False,\n",
+ "\t\t'two': False,\n",
+ "\t\t'three': False,\n",
+ "\t\t'four': True,\n",
+ "\t\t'five': True\n",
+ "\t}, False),\n",
+ "\t({\n",
+ "\t\t'one': False,\n",
+ "\t\t'two': True,\n",
+ "\t\t'three': False,\n",
+ "\t\t'four': False,\n",
+ "\t\t'five': False\n",
+ "\t}, True),\n",
+ "\t({\n",
+ "\t\t'one': True,\n",
+ "\t\t'two': False,\n",
+ "\t\t'three': False,\n",
+ "\t\t'four': False,\n",
+ "\t\t'five': True\n",
+ "\t}, False)\n",
+ "]\n",
+ "```\n",
+ "\n",
+ "To help you in this step, watch the [following video](https://www.youtube.com/watch?v=-vVskDsHcVc) to learn how to build the feature set with Python and NLTK. The source code in this video can be found [here](https://pythonprogramming.net/words-as-features-nltk-tutorial/)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "[](https://www.youtube.com/watch?v=-vVskDsHcVc)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 80,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " wa | \n",
+ " day | \n",
+ " good | \n",
+ " get | \n",
+ " like | \n",
+ " go | \n",
+ " quot | \n",
+ " love | \n",
+ " work | \n",
+ " got | \n",
+ " ... | \n",
+ " freeze | \n",
+ " supper | \n",
+ " hummingbird | \n",
+ " playlist | \n",
+ " alt | \n",
+ " unusual | \n",
+ " provide | \n",
+ " craziness | \n",
+ " yoo | \n",
+ " lurve | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " True | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " True | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 19995 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 19996 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 19997 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 19998 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " True | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 19999 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
20000 rows × 5000 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " wa day good get like go quot love work got \\\n",
+ "0 True False False False False False False False False False \n",
+ "1 False False False False False False False False False True \n",
+ "2 False False False False False False False False False False \n",
+ "3 False False False False False False False False False False \n",
+ "4 False False False False False False False False False False \n",
+ "... ... ... ... ... ... ... ... ... ... ... \n",
+ "19995 False False False False False False False False False False \n",
+ "19996 False False False False False False False False False False \n",
+ "19997 False False False False False False False False False False \n",
+ "19998 False False False True False False False False False False \n",
+ "19999 False False False False False False False False False False \n",
+ "\n",
+ " ... freeze supper hummingbird playlist alt unusual provide \\\n",
+ "0 ... False False False False False False False \n",
+ "1 ... False False False False False False False \n",
+ "2 ... False False False False False False False \n",
+ "3 ... False False False False False False False \n",
+ "4 ... False False False False False False False \n",
+ "... ... ... ... ... ... ... ... ... \n",
+ "19995 ... False False False False False False False \n",
+ "19996 ... False False False False False False False \n",
+ "19997 ... False False False False False False False \n",
+ "19998 ... False False False False False False False \n",
+ "19999 ... False False False False False False False \n",
+ "\n",
+ " craziness yoo lurve \n",
+ "0 False False False \n",
+ "1 False False False \n",
+ "2 False False False \n",
+ "3 False False False \n",
+ "4 False False False \n",
+ "... ... ... ... \n",
+ "19995 False False False \n",
+ "19996 False False False \n",
+ "19997 False False False \n",
+ "19998 False False False \n",
+ "19999 False False False \n",
+ "\n",
+ "[20000 rows x 5000 columns]"
+ ]
+ },
+ "execution_count": 80,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bag_of_words = [word for word, _ in top_words]\n",
+ "num_documents = len(df['text_processed'])\n",
+ "num_words = len(bag_of_words)\n",
+ "features = np.zeros((num_documents, num_words), dtype=bool)\n",
+ "\n",
+ "for i, words_list in enumerate(df['text_processed']):\n",
+ " for word in words_list:\n",
+ " if word in bag_of_words:\n",
+ " word_index = bag_of_words.index(word)\n",
+ " features[i, word_index] = True\n",
+ "\n",
+ "feature_data = {word: features[:, i] for i, word in enumerate(bag_of_words)}\n",
+ "data = pd.DataFrame(feature_data)\n",
+ "\n",
+ "data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 82,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "[nltk_data] Downloading package vader_lexicon to\n",
+ "[nltk_data] C:\\Users\\josep\\AppData\\Roaming\\nltk_data...\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " wa | \n",
+ " day | \n",
+ " good | \n",
+ " get | \n",
+ " like | \n",
+ " go | \n",
+ " quot | \n",
+ " love | \n",
+ " work | \n",
+ " got | \n",
+ " ... | \n",
+ " supper | \n",
+ " hummingbird | \n",
+ " playlist | \n",
+ " alt | \n",
+ " unusual | \n",
+ " provide | \n",
+ " craziness | \n",
+ " yoo | \n",
+ " lurve | \n",
+ " is_positive | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " True | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " True | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 19995 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 19996 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 19997 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 19998 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " True | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 19999 | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " ... | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
20000 rows × 5001 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " wa day good get like go quot love work got \\\n",
+ "0 True False False False False False False False False False \n",
+ "1 False False False False False False False False False True \n",
+ "2 False False False False False False False False False False \n",
+ "3 False False False False False False False False False False \n",
+ "4 False False False False False False False False False False \n",
+ "... ... ... ... ... ... ... ... ... ... ... \n",
+ "19995 False False False False False False False False False False \n",
+ "19996 False False False False False False False False False False \n",
+ "19997 False False False False False False False False False False \n",
+ "19998 False False False True False False False False False False \n",
+ "19999 False False False False False False False False False False \n",
+ "\n",
+ " ... supper hummingbird playlist alt unusual provide craziness \\\n",
+ "0 ... False False False False False False False \n",
+ "1 ... False False False False False False False \n",
+ "2 ... False False False False False False False \n",
+ "3 ... False False False False False False False \n",
+ "4 ... False False False False False False False \n",
+ "... ... ... ... ... ... ... ... ... \n",
+ "19995 ... False False False False False False False \n",
+ "19996 ... False False False False False False False \n",
+ "19997 ... False False False False False False False \n",
+ "19998 ... False False False False False False False \n",
+ "19999 ... False False False False False False False \n",
+ "\n",
+ " yoo lurve is_positive \n",
+ "0 False False True \n",
+ "1 False False False \n",
+ "2 False False False \n",
+ "3 False False False \n",
+ "4 False False False \n",
+ "... ... ... ... \n",
+ "19995 False False True \n",
+ "19996 False False True \n",
+ "19997 False False False \n",
+ "19998 False False False \n",
+ "19999 False False False \n",
+ "\n",
+ "[20000 rows x 5001 columns]"
+ ]
+ },
+ "execution_count": 82,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "nltk.download('vader_lexicon')\n",
+ "\n",
+ "# Initialize the SentimentIntensityAnalyzer\n",
+ "sia = SentimentIntensityAnalyzer()\n",
+ "\n",
+ "# Create a function to determine sentiment based on text\n",
+ "def get_sentiment(text):\n",
+ " scores = sia.polarity_scores(text)\n",
+ " compound_score = scores['compound']\n",
+ " return compound_score > 0\n",
+ "\n",
+ "# Apply sentiment analysis to each row in the DataFrame\n",
+ "data['is_positive'] = data.apply(lambda row: get_sentiment(' '.join(row.index[row])), axis=1)\n",
+ "data"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Building and Traininng Naive Bayes Model\n",
+ "\n",
+ "In this step you will split your feature set into a training and a test set. Then you will create a Bayes classifier instance using `nltk.NaiveBayesClassifier.train` ([example](https://www.nltk.org/book/ch06.html)) to train with the training dataset.\n",
+ "\n",
+ "After training the model, call `classifier.show_most_informative_features()` to inspect the most important features. The output will look like:\n",
+ "\n",
+ "```\n",
+ "Most Informative Features\n",
+ "\t snow = True False : True = 34.3 : 1.0\n",
+ "\t easter = True False : True = 26.2 : 1.0\n",
+ "\t headach = True False : True = 20.9 : 1.0\n",
+ "\t argh = True False : True = 17.6 : 1.0\n",
+ "\tunfortun = True False : True = 16.9 : 1.0\n",
+ "\t jona = True True : False = 16.2 : 1.0\n",
+ "\t ach = True False : True = 14.9 : 1.0\n",
+ "\t sad = True False : True = 13.0 : 1.0\n",
+ "\t parent = True False : True = 12.9 : 1.0\n",
+ "\t spring = True False : True = 12.7 : 1.0\n",
+ "```\n",
+ "\n",
+ "The [following video](https://www.youtube.com/watch?v=rISOsUaTrO4) will help you complete this step. The source code in this video can be found [here](https://pythonprogramming.net/naive-bayes-classifier-nltk-tutorial/)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "[](https://www.youtube.com/watch?v=rISOsUaTrO4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Testing Naive Bayes Model\n",
+ "\n",
+ "Now we'll test our classifier with the test dataset. This is done by calling `nltk.classify.accuracy(classifier, test)`.\n",
+ "\n",
+ "As mentioned in one of the tutorial videos, a Naive Bayes model is considered OK if your accuracy score is over 0.6. If your accuracy score is over 0.7, you've done a great job!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 84,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Most Informative Features\n",
+ " ('aa', 6) = False neg : pos = 1.0 : 1.0\n",
+ " ('aaa', 3) = False neg : pos = 1.0 : 1.0\n",
+ " ('aaaaaah', 3) = False neg : pos = 1.0 : 1.0\n",
+ " ('aaah', 5) = False neg : pos = 1.0 : 1.0\n",
+ " ('aah', 5) = False neg : pos = 1.0 : 1.0\n",
+ " ('aahh', 3) = False neg : pos = 1.0 : 1.0\n",
+ " ('aaron', 4) = False neg : pos = 1.0 : 1.0\n",
+ " ('abandoned', 3) = False neg : pos = 1.0 : 1.0\n",
+ " ('abby', 4) = False neg : pos = 1.0 : 1.0\n",
+ " ('ability', 3) = False neg : pos = 1.0 : 1.0\n",
+ "Accuracy: 0.465\n"
+ ]
+ }
+ ],
+ "source": [
+ "# your code here\n",
+ "# Shuffle the data\n",
+ "random.shuffle(featuresets)\n",
+ "\n",
+ "# Split the featuresets into training and test sets\n",
+ "train_size = int(0.8 * len(featuresets))\n",
+ "train_set = featuresets[:train_size]\n",
+ "test_set = featuresets[train_size:]\n",
+ "\n",
+ "# Train the Naive Bayes classifier\n",
+ "classifier = nltk.NaiveBayesClassifier.train(train_set)\n",
+ "\n",
+ "# Show the most informative features\n",
+ "classifier.show_most_informative_features()\n",
+ "\n",
+ "# Evaluate the classifier on the test set\n",
+ "accuracy = nltk.classify.accuracy(classifier, test_set)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Bonus Question 1: Improve Model Performance\n",
+ "\n",
+ "If you are still not exhausted so far and want to dig deeper, try to improve your classifier performance. There are many aspects you can dig into, for example:\n",
+ "\n",
+ "* Improve stemming and lemmatization. Inspect your bag of words and the most important features. Are there any words you should furuther remove from analysis? You can append these words to further remove to the stop words list.\n",
+ "\n",
+ "* Remember we only used the top 5,000 features to build model? Try using different numbers of top features. The bottom line is to use as few features as you can without compromising your model performance. The fewer features you select into your model, the faster your model is trained. Then you can use a larger sample size to improve your model accuracy score."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# your code here"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Bonus Question 2: Machine Learning Pipeline\n",
+ "\n",
+ "In a new Jupyter Notebook, combine all your codes into a function (or a class). Your new function will execute the complete machine learning pipeline job by receiving the dataset location and output the classifier. This will allow you to use your function to predict the sentiment of any tweet in real time. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# your code here"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Bonus Question 3: Apache Spark\n",
+ "\n",
+ "If you have completed the Apache Spark advanced topic lab, what you can do is to migrate your pipeline from local to a Databricks Notebook. Share your notebook with your instructor and classmates to show off your achievements!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# your code here"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.12"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}