Skip to content

Instantly share code, notes, and snippets.

View zachmayer's full-sized avatar

Zach Deane-Mayer zachmayer

View GitHub Profile
program hello
print *, "Hello World!"
end program hello
@zachmayer
zachmayer / magic_future_computation.R
Created September 16, 2015 19:50
Sparse != Big Data
#Define the problem
t1 <- Sys.time()
set.seed(1)
n_nodes <- 300000L
n_edges <- 900000L
nodes <- 1L:n_nodes
edge_node_1 <- sample(nodes, n_edges, replace=TRUE)
edge_node_2 <- sample(nodes, n_edges, replace=TRUE)
#Sparse matrix
@zachmayer
zachmayer / 1. Install Packages.R
Created May 3, 2011 14:34
Kaggle introduction
install.packages(c("caret","reshape2","plyr","caTools"),dependencies=c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances"))
@zachmayer
zachmayer / 1. Parameters.R
Created May 12, 2011 18:21
Kaggle Competition Walkthrough: Fitting a model
####################################
# Training parameters
####################################
MyTrainControl=trainControl(
method = "repeatedCV",
number=10,
repeats=5,
returnResamp = "all",
classProbs = TRUE,
summaryFunction=twoClassSummary
@zachmayer
zachmayer / 1. Setup.R
Created June 1, 2011 17:56
Kaggle Competition Walkthrough: Wrapup
#Setup
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE
#Directory
setwd("~/Overfitting")
#Load Required Packages
library('caTools')
library('caret')
library('glmnet')
@zachmayer
zachmayer / Example.R
Created July 1, 2011 15:33
Example code for casualfactors
library(quantmod)
getSymbols(c('AHETPI','CES0500000003','CPIAUCSL','GASREGM'),src = "FRED")
getSymbols('XAU/USD',src = "oanda")
#Definitions:
#AHETPI = Average Hourly Earnings of Production and Nonsupervisory Employees: Total Private
#CES0500000003 = Average Hourly Earnings of All Employees: Total Private
#CPIAUCSL = Consumer Price Index for All Urban Consumers: All Items
#GASREGM = US Regular All Formulations Gas Price
#XAUUSD USD per 1 oz of gold. Last 500 days only
@zachmayer
zachmayer / multiRF.R
Created July 22, 2011 13:55
multiRF.R
multiRF <- function(x,...) {
foreach(i=x,.combine=combine,.packages='randomForest',
.export=c('X','Y'),.inorder=FALSE) %dopar% {
randomForest(X,Y,mtry=i,...)
}
}
multiRF(c(rep(3,10),rep(4,10),rep(5,10)),ntree=500)
@zachmayer
zachmayer / Run.R
Created August 10, 2011 17:59
R googlepredictionapi
## Load googlepredictionapi and dependent libraries
library(rjson)
library(RCurl)
library(googlepredictionapi)
#Save dataframe to a file, upload to google storage, and train a model
write.csv(iris,'iris.csv')
model <- PredictionApiTrain(data='iris.csv', remote.file="gs://rdata/iris")
#Summarize model and predict for new data
@zachmayer
zachmayer / 1. Compare 1 month.R
Created August 22, 2011 15:47
Recession forecasting II- Hussman's Accuracy
#Actual Recessions
getSymbols('USREC',src='FRED')
USREC <- USREC["1997-07-01::",] #Start from same period
#Compare recession now to warning last month
library(caret)
OneMonth <- Lag(P.Rec)
compare <- na.omit(merge(OneMonth,USREC))
confusionMatrix(compare[,1],compare[,2],positive = '1')
@zachmayer
zachmayer / 0. Plain.R
Created August 23, 2011 15:13
Variable Interactions
cor(iris[-5])
pairs(iris[-5], bg=iris$Species, pch=21)