Skip to content

Instantly share code, notes, and snippets.

@joelkr
joelkr / Setup.R
Created June 22, 2014 23:11
R data munging file for UC Irvine Cardiac Arrythmia File
cardiac <- read.csv("arrhythmia.data", header=F, na.strings="?")
colnames(cardiac)[1:280] <- c("Age","Gender_Nom","Height","Weight","QRS_Dur",
"P-R_Int","Q-T_Int","T_Int","P_Int","QRS","T","P","QRST","J","Heart_Rate",
"Q_Wave","R_Wave","S_Wave","R_Prime","S_Prime","Int_Def","Rag_R_Nom",
"Diph_R_Nom","Rag_P_Nom","Diph_P_Nom","Rag_T_Nom","Diph_T_Nom",
"DII00", "DII01","DII02", "DII03", "DII04","DII05","DII06","DII07","DII08","DII09","DII10","DII11",
"DIII00","DIII01","DIII02", "DIII03", "DIII04","DIII05","DIII06","DIII07","DIII08","DIII09","DIII10","DIII11",
"AVR00","AVR01","AVR02","AVR03","AVR04","AVR05","AVR06","AVR07","AVR08","AVR09","AVR10","AVR11",
"AVL00","AVRL1","AVL02","AVL03","AVL04","AVL05","AVL06","AVL07","AVL08","AVL09","AVL10","AVL11",
"AVF00","AVF01","AVF02","AVF03","AVF04","AVF05","AVF06","AVF07","AVF08","AVF09","AVF10","AVF11",
@joelkr
joelkr / CollaborativeFiltering.R
Created June 22, 2014 23:55
R Functions for Collaborative Filtering Cardiac Arrythmia Data
# Cost and gradient functions for optim(). These are a port of Coursera
# Machine Learning course topic Collaborative Filtering from MATLAB
# to R.
# Cost Function
coFilterCost <- function (params, npatients, nleads, nreadings,Y, R, lambda)
{
# params: X and Theta flattened to vector
# npatients, nleads, nreadings: number of patients, leads, and numeric
# fields in data
@joelkr
joelkr / Test.R
Last active August 29, 2015 14:02
Testing Collaborative Filtering on the Cardiac Arrythmia Data
# Try setting up a smaller test set
# Variables to set how large a square of data to test
npatients <- 4
nreadings <- 8
# We are still not converging in 500 trials. Perhaps we have too many unknowns.
#nleads <- 10
nleads <- 12
load("cardiacSetup.rda")
# BayesProbability.R
#set.seed(49)
# Build a dummy dictionary
a <- letters
b <- letters
tokens <- apply(expand.grid(a, b), 1, function(x) paste(x, collapse=""))
# Number of tokens to use 1-676
tl <- 100
@joelkr
joelkr / handy.R
Created February 6, 2015 16:48
NASA HANDY Model in R
library(deSolve)
handyMod <- function(Time, State, Pars) {
with(as.list(c(State, Pars)), {
# First calculate threshold below which famine begins
# rho = minimum required consumption
wThresh = rho * popC + rho * kappa * popE
# Check to avoid dividing by zero then estimate consumption of
# commons = cC and elites = cE
if(wThresh > 0) {
@joelkr
joelkr / Dockerfile
Created March 3, 2017 15:38
Docker file for kaggle
FROM ubuntu:16.04
#FROM ubuntu:14.04
# Extended and moved to python 3 based on image:
#MAINTAINER Wise.io, Inc. <[email protected]>
ENV DEBIAN_FRONTEND noninteractive
ENV PATH /anaconda/bin:$PATH
# For image inheritance.
ONBUILD ENV PATH /anaconda/bin:$PATH
@joelkr
joelkr / docker-compose.yml
Created March 3, 2017 16:06
docker-compose.yml for kaggle
notebook:
image: my-data-science-docker:0.1
ports:
- "80:8888"
environment:
- WISEDS_CODE_DIR=${PWD}
- WISEDS_DATA_DIR=${PWD}/data
# - IPYTHON_PASSWORD=WhoMe321
- PASSWORD=WhoMe321
- KERAS_BACKEND=theano