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(yaml) | |
library(RJSONIO) | |
library(httr) | |
event_id <- 132296372 | |
n_max <- 20 | |
api_key <- yaml.load_file("meetup_api_key.yml")$api_key | |
## get your api key from http://www.meetup.com/meetup_api/key/ while logged in |
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(Matrix) | |
rm(list=ls()) | |
set.seed(123) | |
## parameters | |
n <- 1e6 |
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(RJSONIO) | |
library(httr) | |
library(ggplot2) | |
api_key <- scan("~/.meetup.apikey", character(), quiet = TRUE) | |
group_id <- 1414043 ## LA R meetup | |
req_url <- paste0("http://www.meetup.com/2/events?key=", api_key, | |
"&group_id=",group_id,"&status=past") | |
events_data <- fromJSON(rawToChar(GET(req_url)$content))$results |
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
--- | |
runtime: shiny | |
output: html_document | |
--- | |
```{r, echo=FALSE} | |
inputPanel( | |
selectInput("n", label = "n:", choices = c(10,50)), | |
submitButton("Update") |
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(dplyr) | |
read.csv("members_export.csv") %>% | |
mutate(pcrnk = percent_rank(CONFIRM_TIME), wdbl = ifelse(LinkedIn!="",2,1), | |
w = (3-2*pcrnk)*wdbl) %>% | |
sample_n(30, weight = w) %>% | |
mutate(name = paste(First.Name,Last.Name)) %>% select(name) |
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
## Minimal example of R's data.table vs pandas aggregation and join benchmark | |
## ( more detailed but still basic benchmark here: | |
## http://datascience.la/dplyr-and-a-very-basic-benchmark/ ) | |
## Just copy paste into R and Ipython, respectively | |
## Timings on a decent server with data.table 1.9.4 & pandas 0.15.1 (Nov 2014) | |
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
abbr <- input$inp_abbr | |
dbGetQuery(con, paste0("select * from states where abbr = '",abbr,"'")) |
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
abbr <- validinp_character(input$inp_abbr) | |
## or: | |
abbr <- validinp_character(input$inp_abbr, pattern="^((CA)|(NY))$") |
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(randomForest) | |
library(parallel) | |
genr_data <- function(n,p) { | |
X <- matrix(rnorm(n*p),n,p) | |
y <- as.factor(apply(X,1, function(x) | |
ifelse(sum(x^2)>qchisq(0.5,p),"+","-"))) | |
## Hastie etal 10.2 | |
data.frame(X,y) |
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
import numpy as np | |
from scipy.stats import chi2 | |
from sklearn.ensemble import RandomForestClassifier | |
n = 1000 | |
p = 100 | |
def genr_data(n,p): | |
X = np.random.randn(n,p) | |
y = np.zeros(n) |
OlderNewer