Skip to content

Instantly share code, notes, and snippets.

John Ramey ramhiser

Block or report user

Report or block ramhiser

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Keybase proof

I hereby claim:

  • I am ramhiser on github.
  • I am ramhiser ( on keybase.
  • I have a public key ASBotXs-LlQCC_m4Y3nVJlvF-fOMjq9idZtoXkYd-jekzQo

To claim this, I am signing this object:

ramhiser / changepoint-linear-regression.r
Last active May 21, 2019
Bayesian changepoint detection in linear regression with R and Stan
View changepoint-linear-regression.r
# Based on this blog post:
rstan_options(auto_write = TRUE)
beta0 <- 3
beta1 <- 9
beta2 <- 15
ramhiser /
Created May 31, 2017
JSON Export of a scikit-learn Pipeline object
import json
def fullname(o):
return o.__module__ + "." + o.__class__.__name__
def export_pipeline(scikit_pipeline):
"""JSON export of a scikit-learn pipeline.
Especially useful when paired with GridSearchCV, TPOT, etc.
ramhiser /
Last active May 31, 2017
Confidence Interval for the mean of a Normal distribution using scipy and Pythonn
from scipy import stats
import numpy as np
def mean_confidence_interval(x, alpha=0.05):
"""Computes two-sided confidence interval for a Normal mean
Assumes population variance is unknown.
x is assumed to be a list or a 1-d Numpy array
ramhiser / brms-nonlinear.r
Last active Oct 4, 2017
Adding fixed effects and random effects to a nonlinear Stan model via brms
View brms-nonlinear.r
# The data set and model are described in the *brms* vignette
url <- paste0("")
loss <- read.csv(url)
# Generated a random continuous feature
loss$ramey <- runif(nrow(loss))
ramhiser / illustrate-overfit.r
Last active Jul 24, 2018
An illustration of underfitting and overfitting on an unknown curve compared with a random forest
View illustrate-overfit.r
num_points <- 20
x <- sort(runif(num_points, min=-5, max=6))
y <- x^2/5 + sin(3*x) # + rnorm(num_points, sd=0.1)
df <- data_frame(x=x, y=y)
ramhiser / stan-dogs.r
Created Mar 3, 2017
Stan Implementation of a Log-linear Model for the Dogs Data Set
View stan-dogs.r
# The Dogs data set was analyzed by D.V. Lindley using a loglinear model for binary data
# For details about the Dogs data set and model, see:
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
num_dogs <- 30
num_trials <- 25
Y <- structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ramhiser / character2factor.r
Created Feb 10, 2017
Convert all character columns to factors using dplyr in R
View character2factor.r
iris_char <- iris %>%
char_column=sample(letters[1:5], nrow(iris), replace=TRUE))
sum(sapply(iris_char, is.character)) # 2
iris_factor <- iris_char %>%
mutate_if(sapply(iris_char, is.character), as.factor)
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species char_column
# "numeric" "numeric" "numeric" "numeric" "character" "character"
ramhiser / stratify.r
Last active Sep 6, 2019
Stratified Sampling in R with dplyr
View stratify.r
# Uses a subset of the Iris data set with different proportions of the Species factor
iris_subset <- iris[c(1:50, 51:80, 101:120), ]
stratified_sample <- iris_subset %>%
group_by(Species) %>%
mutate(num_rows=n()) %>%
sample_frac(0.4, weight=num_rows) %>%
ramhiser / symmetric-MAPE.r
Created Jan 12, 2017
Symmetric MAPE following visualization in Figure 3c of the MAAPE Paper
View symmetric-MAPE.r
A <- seq(0, 10, length=100)
F <- seq(0, 10, length=100)
symmetric_mape <- function(A, F) {
abs(F - A) / (abs(A) + abs(F))
You can’t perform that action at this time.