Skip to content

Instantly share code, notes, and snippets.

View DexGroves's full-sized avatar

DG DexGroves

  • London
View GitHub Profile
library("mlbench")
library("gbm")
library("ggplot2")
get_spiral_df <- function(N, cycles, sd) {
spiral_data <- mlbench.spirals(N, cycles, sd)
data.frame(x = spiral_data$x[, 1],
y = spiral_data$x[, 2],
class = as.numeric(spiral_data$classes) - 1)
@DexGroves
DexGroves / peter_susan_and_barack.py
Created April 1, 2016 13:39
fivethirtyeight riddler for April 1st 2016
import itertools
import numpy as np
from collections import Counter
def person_says_no(possibilities):
uniqueness = Counter([d.values()[0]
for d in possibilities]).items()
impossibilities = [x for (x, count) in uniqueness if count == 1]
strip_glm <- function(cm) {
cm$y = c()
cm$model = c()
cm$residuals = c()
cm$fitted.values = c()
cm$effects = c()
cm$qr$qr = c()
cm$linear.predictors = c()
cm$weights = c()
strip_glm <- function(cm) {
cm$y = c()
cm$model = c()
cm$residuals = c()
cm$fitted.values = c()
cm$effects = c()
cm$qr$qr = c()
cm$linear.predictors = c()
cm$weights = c()
library("data.table")
fread("a,b\n1,T\n1,T\n1,T\n1,T\n1,T\n2,C\n")
# a b
# 1: 1 1
# 2: 1 1
# 3: 1 1
# 4: 1 1
# 5: 1 1
@DexGroves
DexGroves / xgboost_sparse_dense_different_model.R
Created March 1, 2016 11:24
xgboost creating different model structures based on choice of sparsity
library("data.table")
library("xgboost")
library("Matrix")
generate_data <- function(N) {
data.table(
response = as.numeric(runif(N) > 0.8),
float1 = rnorm(N, 3, 3))
}
@DexGroves
DexGroves / xgboost_sparse_zeroes.R
Created March 1, 2016 10:37
xgboost sending sparse zeroes to missing node
library("data.table")
library("xgboost")
library("Matrix")
generate_data <- function(N) {
data.table(
response = as.numeric(runif(N) > 0.8),
int1 = round(rnorm(N, 3, 3))
)
library("data.table")
library("xgboost")
library("Matrix")
generate_data <- function(N) {
data.table(
response = as.numeric(runif(N) > 0.8),
int1 = round(rnorm(N, 3, 3)),
int2 = round(rnorm(N, 3, 3)),
@DexGroves
DexGroves / riddler_jan22.R
Created January 22, 2016 14:57
Stop ruining my Fridays fivethirtyeight.
library("igraph")
library("stringi")
library("magrittr")
generate_bridge_df <- function(nrow, ncol) {
this_layer <- generate_layer(ncol)
first_connections <- data.frame(from = "Northside",
to = get_layer_vertices(this_layer))
all_bridges <- rbind(first_connections, this_layer)
library("Rcpp")
library("microbenchmark")
simulate_throws <- cppFunction('
double simulate_throw(NumericVector start, int nthrows, int trials) {
int trials_so_far = 0;
int final_throw_successes_so_far = 0;
int hits_so_far = 0;
int nstart = start.size();