Coder Social home page Coder Social logo

kevinmcdermott062 / botrnot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mkearney/tweetbotornot

0.0 2.0 0.0 21.72 MB

R package for detecting Twitter bots via machine learning

Home Page: https://github.com/mkearney/botornot

License: Other

R 100.00%

botrnot's Introduction

botrnot

An R package for classifying Twitter accounts as bot or not.

Features

Uses machine learning to classify Twitter accounts as bots or not bots. The default model is 93.53% accurate when classifying bots and 95.32% accurate when classifying non-bots. The fast model is 91.78% accurate when classifying bots and 92.61% accurate when classifying non-bots.

Overall, the default model is correct 93.8% of the time.

Overall, the fast model is correct 91.9% of the time.

Install

Install from Github.

if (!requireNamespace("devtools", quietly = TRUE)) {
  install.packages("devtools")
}
devtools::install_github("mkearney/botrnot")

API authorization

Users must be authorized in order to interact with Twitter's API. To setup your machine for authorized request, see these instructions provided in the rtweet package.

Usage

There's one function botornot(). Give it a vector of screen names or user IDs and let it go to work.

## load package
library(botrnot)

## select users
users <- c("realdonaldtrump", "netflix_bot",
  "kearneymw", "dataandme", "hadleywickham",
  "ma_salmon", "juliasilge", "tidyversetweets", 
  "American__Voter", "mothgenerator", "hrbrmstr")

## get botornot estimates
data <- botornot(users)

## arrange by prob ests
data[order(data$prob_bot), ]
#> # A tibble: 11 x 2
#>    user            prob_bot
#>    <chr>              <dbl>
#>  1 hadleywickham    0.00290
#>  2 realDonaldTrump  0.00753
#>  3 kearneymw        0.0171 
#>  4 ma_salmon        0.0582 
#>  5 juliasilge       0.0852 
#>  6 hrbrmstr         0.0858 
#>  7 dataandme        0.174  
#>  8 netflix_bot      0.974  
#>  9 tidyversetweets  0.997  
#> 10 mothgenerator    0.999  
#> 11 American__Voter  0.999

Integration with rtweet

The botornot() function also accepts data returned by rtweet functions.

## load rtweet
library(rtweet)
#> 
#> Attaching package: 'rtweet'
#> The following object is masked from 'package:tfse':
#> 
#>     round_time

## get most recent 100 tweets from each user
tmls <- get_timelines(users, n = 100)

## pass the returned data to botornot()
data <- botornot(tmls)

## arrange by prob ests
data[order(data$prob_bot), ]
#> # A tibble: 11 x 2
#>    user            prob_bot
#>    <chr>              <dbl>
#>  1 hadleywickham    0.00290
#>  2 realDonaldTrump  0.00753
#>  3 kearneymw        0.0171 
#>  4 ma_salmon        0.0582 
#>  5 juliasilge       0.0852 
#>  6 hrbrmstr         0.0858 
#>  7 dataandme        0.174  
#>  8 netflix_bot      0.974  
#>  9 tidyversetweets  0.997  
#> 10 mothgenerator    0.999  
#> 11 American__Voter  0.999

fast = TRUE

The default [gradient boosted] model uses both users-level (bio, location, number of followers and friends, etc.) and tweets-level (number of hashtags, mentions, capital letters, etc. in a user's most recent 100 tweets) data to estimate the probability that users are bots. For larger data sets, this method can be quite slow. Due to Twitter's REST API rate limits, users are limited to only 180 estimates per every 15 minutes.

To maximize the number of estimates per 15 minutes (at the cost of being less accurate), use the fast = TRUE argument. This method uses only users-level data, which increases the maximum number of estimates per 15 minutes to 90,000! Due to losses in accuracy, this method should be used with caution!

## get botornot estimates
data <- botornot(users, fast = TRUE)

## arrange by prob ests
data[order(data$prob_bot), ]
#> # A tibble: 11 x 2
#>    user            prob_bot
#>    <chr>              <dbl>
#>  1 hadleywickham    0.00316
#>  2 kearneymw        0.0333 
#>  3 ma_salmon        0.0385 
#>  4 hrbrmstr         0.0478 
#>  5 juliasilge       0.0640 
#>  6 dataandme        0.245  
#>  7 realDonaldTrump  0.380  
#>  8 netflix_bot      0.986  
#>  9 tidyversetweets  0.997  
#> 10 American__Voter  0.998  
#> 11 mothgenerator    0.999

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.