Asset Classes

Free investment financial education

More Campus Resources

Useful Tools and Information

Language

Multilingual content from IBKR

# Detecting Bots On Twitter Using Botometer – Part II

Varun Divakar
QuantInsti

#### Temporal features

The category temporal features analyze the tweet rate, timing patterns of tweeting and retweeting, etc. For example, if the account tweets at the same time intervals, then it is most likely a bot.

Election Tweets: Identifying the bots

India recently conducted its general election. And there are many bots on Twitter supporting their political parties. It is important to know which tweets were made by bots. But before that let us check if the botometer is working correctly. Let us take known Twitter handles of real political leaders and check if it is anticipating correctly.

First, we install the botometer library using the pip install as shown below and then instantiate a botometer object.

!pip install botometer

Now let us try with the known handle of U.S. President Donald Trump and see what the botometer says.

@realDonaldTrump is the Twitter handle of the American President. After fetching the bot score for this handle we can print and check it using the following command.

All the bot scores' values are very low on a scale of 0-1, indicating that most likely the user is a human. We can also get the final score or the aggregate using the following command.

Since most of the tweets made by Mr Doanld Trump are in English, we can consider the English score of 0.03 on a scale of 0-1 as the final indicator. In general, we consider a score of more than 0.6 as an indication that an account is being controlled by a bot. So if any of you who had doubts whether the tweets made by the account @realDonaldTrump were really made by the President himself, then these scores should settle that doubt now.

Now let us get back to the Indian election and check how the Twitter handles of the two top candidates performed.

First, let us run the analysis for the current Prime Minister of India: Mr Narender Modi. His Twitter handle is @narendramodi

And his bot scores are

Since some of Mr Narendra Modi’s tweets are in Hindi, we need to consider the universal score in this case. Which again is very low indicating a human user.

Now let us perform the same exercise for the main opposition Prime Minister Candidate: Mr Rahul Gandhi.

Again the score here is very low, indicating a human user. The purpose of this exercise is to check the sanity of the outlooks made by the botometer and they clearly look satisfactory and as expected.

But we have not yet identified the bot followers for these leaders. We can do this by importing the Twitter IDs using the tweepy library and then running the botometer check on each of them. The process of separating bots and calculating the market sentiment might seem like a very difficult task, but it can be done easily with proper preprocessing. In our new course on Sentiment Analysis in Trading we show you how to fetch the tweets related to a stock using conditional statements and then perform the pre-processing to identify and remove the unrelated tweets. We then generate the market sentiment and create a trading strategy based on this.

Conclusion

The botometer library is built specifically for analyzing the Twitter feed. It is a very important library in the preprocessing of Twitter data before the data can be used to create a trading strategy. Building the gauging of market sentiment is a very difficult task and it needs data from various sources. And all data cannot be treated the same way. So, you need to develop new techniques to preprocess data from blogs and news articles.

###### Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.