Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / quality.R
Created April 27, 2016 22:02
Heathcare quality and detecting poor care with logistic regression.
library('caTools')
library('ROCR')
data <- read.csv('quality.csv')
# 98 received good care (0), 33 poor care (1).
table(data$PoorCare)
rbPal <- colorRampPalette(c('red','blue'))
data$col <- rbPal(10)[as.numeric(cut(data$PoorCare, breaks = 10))]
@primaryobjects
primaryobjects / framingham.R
Created May 2, 2016 00:53
Framingham heart study logistic regression model
library(caTools)
library(ROCR)
framingham <- read.csv('framingham.csv')
set.seed(1000)
split <- sample.split(framingham$TenYearCHD, SplitRatio = 0.65)
train <- subset(framingham, split == TRUE)
test <- subset(framingham, split == FALSE)
@primaryobjects
primaryobjects / PollingData.csv
Last active May 2, 2016 17:54
Predicting presidential election winners by polling data and logistic regression.
State Year Rasmussen SurveyUSA DiffCount PropR Republican
Alabama 2004 11 18 5 1 1
Alabama 2008 21 25 5 1 1
Alaska 2004 1 1 1
Alaska 2008 16 6 1 1
Arizona 2004 5 15 8 1 1
Arizona 2008 5 9 1 1
Arizona 2012 8 4 0.833333333 1
Arkansas 2004 7 5 8 1 1
Arkansas 2008 10 5 1 1
@primaryobjects
primaryobjects / songs.R
Created May 2, 2016 18:55
Predicting Top 10 billboard songs using logistic regression.
songs <- read.csv('songs.csv')
table(songs$year == 2010)
table(songs$artistname == 'Michael Jackson')
songs[songs$artistname == 'Michael Jackson' & songs$Top10 == 1, 'songtitle']
table(songs$timesignature)
# or
unique(songs$timesignature)
summary(songs$timesignature)
@primaryobjects
primaryobjects / parole.R
Created May 2, 2016 19:44
Parole dataset logistic regression.
library(caTools)
library(ROCR)
parole <- read.csv('parole.csv')
table(parole$violator)
unique(parole$state)
unique(parole$crime)
@primaryobjects
primaryobjects / loans.R
Last active May 3, 2016 20:01
LendingTree data analysis with logistic regression, predicted profitability of loans.
library(mice)
library(caTools)
library(ROCR)
loans <- read.csv('loans.csv')
# What proportion of the loans in the dataset were not paid in full?
table(loans$not.fully.paid)
table(loans$not.fully.paid)['1'] / nrow(loans)
@primaryobjects
primaryobjects / stevens.R
Created May 4, 2016 18:31
Predicting Supreme Court decisions for Justice Stevens using CART trees and random forests with cross validation.
library(caTools)
library(rpart)
library(rpart.plot)
library(ROCR)
library(randomForest)
library(caret)
library(e1071)
stevens <- read.csv('stevens.csv')
@primaryobjects
primaryobjects / claims.R
Created May 4, 2016 19:37
Predicting insurance claim buckets with D2Hawkeye dataset and CART models.
library(caTools)
library(rpart)
library(rpart.plot)
claims <- read.csv('claimsdata.csv')
table(claims$bucket2009) / nrow(claims)
set.seed(88)
spl <- sample.split(claims$bucket2009, SplitRatio = 0.6)
@primaryobjects
primaryobjects / gruntfile.js
Last active May 4, 2016 19:46
Example grunt file for building an nwjs desktop app package.
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
nwjs: {
options: {
platforms: ['win64', 'osx64'],
buildDir: './builds',
macZip: true
},
src: ['../myapp/**/*']
@primaryobjects
primaryobjects / boston.R
Last active May 5, 2016 16:25
Analysis of Boston real-estate prices using linear regression, CART, and regression tree models.
library(rpart)
library(rpart.plot)
library(caTools)
library(caret)
library(e1071)
boston <- read.csv('boston.csv')
plot(boston$LON, boston$LAT)