This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to get k-fold metrics for all the H2O AutoML models in R | |
# Adapted from: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/automl.html | |
library(h2o) | |
h2o.init() | |
# Import a sample binary outcome train/test set into H2O | |
train <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv") | |
test <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_test_5k.csv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _____ __ __ | |
# |__ / / /__ ____ _____ ____ ____/ / | |
# /_ <______/ / _ \/ __ `/ __ `/ _ \/ __ / | |
# ___/ /_____/ / __/ /_/ / /_/ / __/ /_/ / | |
# /____/ /_/\___/\__, /\__, /\___/\__,_/ | |
# /____//____/ | |
# RTWEET + 3-LEGGED-AUTH DEMO (LITE) | |
# This code demonstrates how to do 3-legged authentication for Twitter | |
# using the {rtweet} package. Based heavily on code from Michael Kearney. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rtweet) | |
library(markovifyR) | |
## Get tweets with "rtweet" | |
## FYI you need to set up "rtweet" beforehand | |
yost_data <- get_timeline("@travisyost", n = 10000) | |
## Take out RTs and create Markov model | |
markov_model <- yost_data %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
n.samples = 25 | |
set.seed(5) | |
rerun(20,rnorm(n.samples)) %>% | |
map_dfr(~data_frame(data = list(.x)), .id = 'samples') %>% | |
mutate(mu = map_dbl(data,mean), | |
se = map_dbl(data,~sd(.x)/sqrt(length(.x))), | |
top = mu +1.96*se, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(furrr) | |
# localhost -> AWS EC2 linux -> Docker running on that -> R | |
# dm_create() and dm_ip() are from an unreleased R pkg I whipped up, dockermachinery | |
# https://github.com/DavisVaughan/dockermachinery | |
# Creates 1 t2.micro EC2 instance | |
dm_create("amazonec2", "dockertest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rstanarm); library(tidyverse) | |
options(mc.cores = parallel::detectCores()) | |
set.seed(42) | |
data("radon") | |
head(treatment_sample) | |
# Some levels have no variance in the outcomes, making likelihood estimates impossible | |
# Adding a tiny bit of noise fixes the problem | |
radon$log_uranium <- rnorm(nrow(radon), radon$log_uranium, 0.05) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(future) | |
trim_model <- function(model, predictor = predict, ..., ignore_warnings = TRUE) { | |
# Cache the correct output | |
true_pred <- predictor(model, ...) | |
# Treat prediction warnings as errors? | |
if (!ignore_warnings) { | |
old_ops <- options(warn = 2) | |
on.exit(options(old_ops)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [[Rcpp::depends(xtensor)]] | |
#include <numeric> | |
#include "xtensor/xmath.hpp" | |
#include "xtensor-r/rarray.hpp" | |
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::plugins(cpp14)]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rtweet) #rtweet API creds should already be set up | |
library(stringi) | |
library(dplyr) | |
friends = get_friends(user="noamross") | |
followers = get_followers("noamross") | |
tweeps_id = distinct(bind_rows(friends, followers)) | |
tweeps_info = lookup_users(tweeps_id$user_id) | |
# A regex for a visit to Durham |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
functions{ | |
// GP: computes noiseless Gaussian Process | |
vector GP(real volatility, real amplitude, vector normal01, int n_x, real[] x ) { | |
matrix[n_x,n_x] cov_mat ; | |
real amplitude_sq_plus_jitter ; | |
amplitude_sq_plus_jitter = amplitude^2 + 1e-6 ; | |
cov_mat = cov_exp_quad(x, amplitude, 1/volatility) ; | |
for(i in 1:n_x){ | |
cov_mat[i,i] = amplitude_sq_plus_jitter ; | |
} |