This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Directory | |
setwd('~/wherever') | |
#Load Required Packages | |
library('caret') | |
library('glmnet') | |
library('ipred') | |
library('e1071') | |
library('caTools') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages(c("caret","reshape2","plyr","caTools"),dependencies=c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################### | |
# Training parameters | |
#################################### | |
MyTrainControl=trainControl( | |
method = "repeatedCV", | |
number=10, | |
repeats=5, | |
returnResamp = "all", | |
classProbs = TRUE, | |
summaryFunction=twoClassSummary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Setup | |
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE | |
#Directory | |
setwd("~/Overfitting") | |
#Load Required Packages | |
library('caTools') | |
library('caret') | |
library('glmnet') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getNews <- function(symbol, number){ | |
# Warn about length | |
if (number>300) { | |
warning("May only get 300 stories from google") | |
} | |
# load libraries | |
library(XML); library(plyr); library(stringr); library(lubridate); | |
library(xts); library(RDSTK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Code to re-create John Hussman's Recession warning index | |
#http://www.hussmanfunds.com/wmc/wmc110801.htm | |
#R code by Zach Mayer | |
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE | |
library(quantmod) | |
################################################# | |
# 1. Credit spreads | |
################################################# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE | |
library(quantmod) | |
#Scrape data from the website | |
library(XML) | |
rawPMI <- readHTMLTable('http://www.ism.ws/ISMReport/content.cfm?ItemNumber=10752') | |
PMI <- data.frame(rawPMI[[1]]) | |
names(PMI)[1] <- 'Year' | |
#Reshape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
OlderNewer