This report presents an exploratory data analysis of the text datasets provided for the SwiftKey text prediction project. The goal is to understand the basic characteristics of the data to inform the development of a predictive text algorithm and a Shiny application. The analysis focuses on three datasets: US blogs, US news, and US Twitter feeds.
A sample of 5,000 lines from each dataset was used for this analysis. The following table summarizes the key statistics.
| Dataset | Lines | Total_Words | Total_Characters | Avg_Words_Per_Line | Max_Line_Length |
|---|---|---|---|---|---|
| Blogs | 5000 | 205555 | 1139725 | 41.11 | 2521 |
| News | 5000 | 170940 | 1013388 | 34.19 | 1373 |
| 5000 | 63747 | 340150 | 12.75 | 140 |
| Dataset | File_Size_MB | Total_Lines | Max_Line_Length |
|---|---|---|---|
| Blogs | 200 | 899288 | 40833 |
| News | 200 | 1010242 | 11385 |
| 150 | 2360148 | 140 |
Visualizations help illustrate the structure and patterns within the text data.
The density plot and boxplot below show the distribution of line lengths across the three datasets. Twitter lines are predictably much shorter, while blogs and news have a wider range.
The most frequent words provide insight into common topics and language use.
A word cloud provides a visual summary of the most prominent terms.
Several interesting patterns emerged from the analysis:
Sentiment on Twitter: The word “love” appears approximately 4.32 times more frequently than the word “hate” in the Twitter sample.
Biostats Reference: One tweet in the sample mentions “biostats”: “Not found in sample”.
Exact Match: The famous quote “A computer once beat me at chess, but it was no match for me at kickboxing” appears exactly 0 time(s) in the Twitter data.
Longest Line: The longest line in the sample comes from the Blogs dataset, with a length of 2521 characters.
Twitter’s Limit: In the Twitter sample, approximately 100% of lines are within the 140-character limit.
The prediction algorithm will be based on an N-gram Language Model with a Stupid Backoff strategy. The development will proceed as follows:
Data Preprocessing: Text will be cleaned by converting to lowercase, removing punctuation, numbers, and extra whitespace.
N-gram Generation: We will build 1-gram (unigram) through 4-gram (fourgram) models from the training corpus.
Prediction Strategy:
Output: The system will return the top 3-5 most likely candidate words for the next word.
A Shiny application will be developed to provide a user-friendly interface for the prediction model. The planned features include:
The interface will be clean and intuitive, designed for a non-technical audience.
This exploratory analysis has provided a solid understanding of the text datasets. The findings on data size, structure, and key patterns will directly inform the development of a robust and efficient text prediction algorithm. The subsequent Shiny application will make this model accessible to end-users. The next steps involve building the N-gram models and prototyping the Shiny app.
Report generated on 2026-09-04