Skip to content

Instantly share code, notes, and snippets.

View euclidjda's full-sized avatar

John Alberg euclidjda

View GitHub Profile
@euclidjda
euclidjda / plot_value_recoveries_since_1945.R
Last active July 26, 2021 17:48
Generate chart of value vs. growth investing recoveries since 1945 based on Kenneth F. French's data library
# Load libraries
library(ggplot2)
library(stringr)
library(scales)
library(ggthemes)
library(PerformanceAnalytics)
library(RColorBrewer)
# The URL for the data
url.name <- "http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp"
@euclidjda
euclidjda / plot_value_vs_growth_5yr_rolling.R
Last active July 26, 2021 17:47
Generate chart of 5-year annualized return of a Value vs. Growth based on Kenneth F. French's data library
# Load libraries
library(ggplot2)
library(stringr)
library(scales)
library(ggthemes)
library(PerformanceAnalytics)
library(RColorBrewer)
# The URL for the data
url.name <- "http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp"
@euclidjda
euclidjda / plot_temporal_accuracy.R
Last active August 29, 2015 14:24
Plot the accuracy of a model trained in R with caret through time
library(plyr)
data <- read.table("rdata-10pct-1973-1999.dat",sep = " ", header = TRUE, na.strings="NULL",
colClasses=c(DATE="character",GVKEY="character",MONTH="character"))
x <- data[1:6]
y <- factor(data$LABEL)
preds.train <- predict(mdl,x)
data$preds <- as.numeric(levels(preds.train))[preds.train]
@euclidjda
euclidjda / plot_class_density_2.R
Last active August 29, 2015 14:23
Plotting class densities example for machine learning classification - example #2
library(ggplot2)
library(mlbench)
data(PimaIndiansDiabetes)
p <- ggplot( PimaIndiansDiabetes,
aes( x=glucose, fill=diabetes))+
geom_histogram(alpha=0.4,position="identity")+
xlab("diabetes")+
scale_y_continuous("Number of Observations")
@euclidjda
euclidjda / plot_class_density_1.R
Last active August 29, 2015 14:23
Plotting class densities for machine learning classification
library(ggplot2)
library(mlbench)
data( PimaIndiansDiabetes )
ggplot( PimaIndiansDiabetes, aes( x=glucose, y=..density..))+
geom_histogram(fill="cornsilk",colour="grey60",size=0.2)+geom_density()+facet_grid( diabetes ~ . )
@euclidjda
euclidjda / plot_class_distrib2D.R
Last active August 29, 2015 14:23
2D contour heatmaps for illustrating factor relationships in machine learning
require(mlbench)
require(rgl)
require(MASS)
require(plot3D)
##' diverging colour palette function with set midpoint
##'
##' returns a palette function that maps values to colours, with
##' a midpoint (defaulting to 0) corresponding to the central colour
##' @title diverging_palette
library(caret)
library(C50)
library(mlbench)
C5CustomSort <- function(x) {
x$model <- factor(as.character(x$model), levels = c("rules","tree"))
x[order(x$trials, x$model, x$splits, !x$winnow),]
}
@euclidjda
euclidjda / c5fit.R
Last active November 29, 2016 16:04
Simple C5.0 Tuning and Training Example
library(caret)
library(C50)
library(mlbench)
fitControl <- trainControl(method = "repeatedcv",
number = 10,
repeats = 10, returnResamp="all")
# Choose the features and classes
data(PimaIndiansDiabetes2)
@euclidjda
euclidjda / populate.js
Last active August 29, 2015 14:04
A node js script for populating a cgm-remote-monitor database with test data
'use strict';
///////////////////////////////////////////////////
// DB Connection setup and utils
///////////////////////////////////////////////////
var mongodb = require('mongodb');
var software = require('./package.json');
var env = require('./env')( );
@euclidjda
euclidjda / populate.pl
Created July 30, 2014 05:26
Script for populating a cgm-remote-monitor
#!/usr/local/bin/perl -w
# This script is intended to be run as a cron job every n-minutes
# Or whatever the equiv is on windows
use strict;
use MongoDB;
use MongoDB::OID;
use POSIX qw(strftime);