Fake Tweets Using Twitter API and Natural Language

- Slides: 1
Fake Tweets: Using Twitter API and Natural Language Processing (NLP) to Analyze Twitter Users Ceylan Can IPHS 200 – Programming Humanity Introduction Methodology Conclusion Politicians are constantly under the scrutiny of the public. Politicians are constantly being judged, evaluated, and occasionally mocked my the public. Social media platforms, such as Twitter, have allowed public figures (e. g. politicians) to connect and interact with the public. There even exist accounts that are created for the sole purpose of mocking either a politician, celebrity, etc. , which are called “parody accounts”. I decided to investigate the similarities (or differences) between a parody account of a particular user and the real account of that user. Additionally, I was curious to see if the parody account based the content on current political events, or if the content was simply mocking the other. I chose to use Twitter as my platform because this social media site is wellsuited for textual analysis, since the majority of the content is text, and it is a popular medium that public figures use to communicate with the world. I thought there was no better candidate than President Donald Trump to perform this analysis, as he is quite an active Twitter user. I compared Donald Trump’s Tweets with that of a Donald Trump Parody account to find the probability that a given Tweet would come from either user. After searching Internet. Tweets for an algorithm could After program, thethe through the that running perform the task I desired, I came across a Git. Hub that had exactly that. The credit for this code goes to Eugene Aiken; I simply altered a few of the parameters, and fed the algorithm with the Twitter users I wished to conduct this analysis. The program was written in Python; therefore, this was the language used for the project. Additionally, Python has various packages/libraries that are well-suited for NLP. I first created a Twitter developer account, which allowed me to use the Twitter API in order to gather the data from the users. The code uses a function called “Tweet. Miner” which mined the Tweets of Real Trump and Parody Trump and put them in a pandas data frame. The two data frames were next merged into one, after which the new data frame was passed through a NLP package in Python called TF-IDF Vectorizer, which pulled out, analyzed, and ranked the n-grams (sequence of n items from a given text) within each Tweet. Next, the Tweets were processed and a model was created in order to classify the Tweets. The data was cleaned and vectorized using Python’s textacy library. The model uses the Grid. Search. CV and Logistic. Regression algorithms from Python’s Sci-kit Learn library. Next, I fed the model training data. To evaluate the performance of the model, I input a Tweet from each user into the model, which output the probability that the Tweet came from each user. This is displayed in the bottom left area of the poster. Zero is associated with Real Trump’s Tweet, while one is associated with Parody Trump’s Tweet. The test shows that the model was fairly accurate in predicting the Twitter user. The algorithm then created a new data frame that contained the predicted probability of each Tweet. Lastly, I found the highest predicted probabilities of each user, which are displayed below. seemed as though the model was not as accurate as I had initially believed. The probabilities were skewed toward the Tweet coming from the parody account, even if the Tweet actually came from Trump’s real account. However, there were several Tweets in which the probability of it coming from the real or the parody account was close to 50/50. The skewedness of the model does point out some inaccuracies in the model; however, it may have other implications. This may demonstrate the difficulty for an algorithm to be able to distinguish what a politician might says versus what a parody might say, illustrating that humans may be better equipped at such a task because a human has more knowledge about the context of a particular Tweet and is able to understand sarcasm or humor better than a machine. Another interesting finding was the similarity in common words used for both users. The list of most common words are for the parody (left) and the real Trump (right) are displayed below. Apart from the profanities of the parody account, it is evident that this user creates content with information that is consistent with political current events, and not solely mockerybased content. On a larger scale, I believe this project touched upon the dangers of the kind of information that can be found online, and whether or not that information is accurate. it Acknowledgements I would like to thank Professor Elkins and Professor Chun for helping me throughout the course, and inspiring me to use unfamiliar methods (i. e. programming) in order to investigate topics that comment on social issues and the role that technology plays in our understanding of humanity. I would also like to thank Eugene Aiken for allowing his code to be open for public use.