Skip to content

Commit

Permalink
Update readme πŸ“ŠπŸ“‰
Browse files Browse the repository at this point in the history
  • Loading branch information
mkearney committed Feb 9, 2020
1 parent 49ef5d6 commit 84f7338
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 115 deletions.
7 changes: 6 additions & 1 deletion R/preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ preprocess_bot.data.table <- function(x, batch_size = 100, ...) {
if (is.null(batch_size) || isFALSE(batch_size) || length(uid) <= batch_size) {
x <- preprocess_bot_group(x)
if (!is_ids(ogusrs)) {
screen_name <- NULL
x <- x[match(tolower(ogusrs), tolower(x[, screen_name])), ]
} else {
x <- x[match(ogusrs, x[, user_id]), ]
Expand Down Expand Up @@ -278,6 +279,9 @@ preprocess_bot_group <- function(data) {
usr_actyr <- NULL
tweets <- NULL

dtime <- NULL
varname <- NULL

##----------------------------------------------------------------------------##
## DTIME (TIME BETWEEN TWEETS) ##
##----------------------------------------------------------------------------##
Expand All @@ -287,7 +291,8 @@ preprocess_bot_group <- function(data) {
m <- m[, .(dtime = c(NA_real_, abs(as.numeric(diff(created_at), "mins")))), by = user_id][
order(user_id, dtime), .(dtime, varname = paste0("dtime", seq_len(.N))), by = user_id]
## create complete version of dtimes (with missing values)
mna <- data.table::data.table(user_id = unique(m[, user_id]))[, .(dtime = NA_real_, varname = paste0("dtime", 1:200)), by = user_id]
mna <- data.table::data.table(user_id = unique(m[, user_id]))[,
.(dtime = NA_real_, varname = paste0("dtime", 1:200)), by = user_id]
## merge the two–removing duplicated rows from the NA dataset
m <- rbind(m, mna)[!duplicated(data.table::data.table(user_id, varname)), ]
## convert from long to wide for each user
Expand Down
15 changes: 10 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ The most influential features in the classifier

```{r, include=FALSE, eval=FALSE}
# idsbot <- c("user_id", "screen_name", "bot")
# mod <- tweetbotornot2:::prep_xgb_model()
# mod$feature_names <- tweetbotornot2:::tweetbotornot_xgb_model_feature_names
# xgboost::xgb.ggplot.importance(xgboost::xgb.importance(
# model = tweetbotornot2:::tweetbotornot_xgb_model,
# trees = 1:1000), measure = "Gain", top_n = 28) +
# model = mod,
# trees = seq_len(tweetbotornot2:::tweetbotornot_xgb_model_best_ntreelimit)),
# measure = "Gain", top_n = 20) +
# ggplot2::scale_fill_viridis_d(begin= 0.05, end = 0.9) +
# dataviz::theme_mwk(12, "Avenir Next LT Pro") +
# dataviz::theme_mwk(14) +
# #ggplot2::coord_cartesian(ylim = c(0, 0.3)) +
# #ggplot2::coord_flip(ylim = c(0, .12)) +
# ggplot2::ggsave("man/figures/README-import.png", width = 9, height = 8,
Expand All @@ -195,15 +198,17 @@ How features contributed to predictions in the original training data:

```{r, include=FALSE, eval=FALSE}
# .d <- tfse::read_RDS("../twbt/data-final-munged.rds")
# mod <- tweetbotornot2:::prep_xgb_model()
# mod$feature_names <- tweetbotornot2:::tweetbotornot_xgb_model_feature_names
#
# png("man/figures/README-shap.png", width = 9, height = 8, units = "in", res = 312)
# par(tcl = -0.175, bty = "n", xaxt = "s", yaxt = "s", col = "#aaaaaa")
# cols <- viridis::viridis_pal(begin = 0.1, end = 0.9)(2)
# suppressWarnings(
# xgboost::xgb.plot.shap(
# data = as.matrix(.d[, -(1:3)]),
# trees = 1:150,
# model = tweetbotornot2:::tweetbotornot_xgb_model,
# trees = seq_len(mod$best_ntreelimit),
# model = mod,
# top_n = 36, n_col = 6,
# discrete_jitter = 0.15, span_loess = 0.35, col_loess = cols[1],
# col = cols[2],
Expand Down
216 changes: 107 additions & 109 deletions docs/index.html

Large diffs are not rendered by default.

Binary file modified docs/reference/figures/README-import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-shap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-shap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 84f7338

Please sign in to comment.