Skip to content

Instantly share code, notes, and snippets.

View DexGroves's full-sized avatar

DG DexGroves

  • London
View GitHub Profile
@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))
}
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
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()
@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]
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 / install_mxnet.sh
Last active March 18, 2017 11:01
install mxnet
sudo apt-get update
sudo apt-get install -y build-essential git libatlas-base-dev libopencv-dev
git clone --recursive https://github.com/dmlc/mxnet
cd mxnet;
cp make/config.mk .
#add CUDA options
echo "USE_CUDA=1" >>config.mk
@DexGroves
DexGroves / spiralmxnet.R
Created April 15, 2016 16:28
Fit mxnet on a spiral
library("mlbench")
library("ggplot2")
library("mxnet")
plot_mxmodel <- function(model, data) {
x <- seq(from = min(data), to = max(data), length.out = 500)
d2 <- as.matrix(expand.grid(x, x))
mx_pred <- predict(model, d2)
# Instantiate local CRAN
localCRAN <- path.expand("QRAN")
dir.create(localCRAN)
contribDir <- file.path(localCRAN, "src", "contrib")
dir.create(contribDir, recursive = TRUE)
rVersion <- paste(unlist(getRversion())[1:2], collapse = ".")
binPaths <- list(
@DexGroves
DexGroves / lupa.R
Created August 19, 2016 17:11
Lowest unique common integer code
generate_fks <- function(N) {
fki <- log(N + 1)
fks <- c(fki)
for (i in seq(N)) {
fki <- log(exp(fki) - fki)
fks <- c(fks, fki)
}
fks