Introduction to Text Classification in R with quanteda

Offered By
Coursera Project Network
In this Guided Project, you will:

Import text documents, reshape texts from documents to paragraphs, and turn your texts into a machine readable format.

Classify presidential concession speeches by political party using a Naive Bayes algorithm and assess the accuracy of the predictions.   

Clock2 hours
BeginnerBeginner
CloudNo download needed
VideoSplit-screen video
Comment DotsEnglish
LaptopDesktop only

In this guided project you will learn how to import textual data stored in raw text files into R, turn these files into a corpus (a collection of textual documents), reshape them into paragraphs from documents and tokenize the text all using the R software package quanteda. You will then learn how to classify the texts using the Naive Bayes algorithm. This guided project is for beginners interested in quantitative text analysis in R. It assumes no knowledge of textual analysis and focuses on exploring textual data (US Presidential Concession Speeches). Users should have a basic understanding of the statistical programming language R.

Skills you will develop

Ordered PairText AnalysisAlgorithmsStatistical Programming LanguagesComputer Programming

Learn step-by-step

In a video that plays in a split-screen with your work area, your instructor will walk you through these steps:

  1. Load text documents into R studio, convert a number of text documents into a corpus, and extract data from text document file names and add them to a new column in a dataframe. 

  2. Reshape the dataset into paragraphs from documents and check for balance in your labels. 

  3. Split up a text document corpus into tokens, or individual words and punctuations. Then clean the data by removing specific words and spellings.

  4. Create a Document Feature Matrix, divide it into train and test sets and run a Naive Bayes model. Then examine the model’s prediction accuracy and learn about accuracy, precision, and recall.   

  5. Run Naive Bayes models for a second and third time. Then examine the models' predictions and compare the model outputs with results from the previous task.

How Guided Projects work

Your workspace is a cloud desktop right in your browser, no download required

In a split-screen video, your instructor guides you step-by-step

Frequently asked questions

Frequently Asked Questions

More questions? Visit the Learner Help Center.