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
def gcd(m,n): | |
while m%n != 0: | |
oldm = m | |
oldn = n | |
m = oldn | |
n = oldm%oldn | |
return n | |
class Fraction: |
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
class Quick: | |
def __init__(self,x): | |
self.ids = {i:i for i in x} | |
self.node = self.ids.keys() | |
self.connect = self.ids.values() | |
self.sz = {i:1 for i in range(len(self.ids))} | |
def root(self, x,compression=True): |
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
def shellSort(x): | |
h = len(x)//2 | |
i = h | |
while h > 0: | |
while i < len(x): | |
for j in range(i,0,-1): | |
if x[j] < x[j-h]: | |
x[j],x[j-h] = x[j-h],x[j] | |
else: | |
break |
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
play <- function(){ | |
possibilities <- c("rock", "Spock", "paper", "lizard", "scissors") | |
cat(possibilities, sep="\n") | |
cat("\n") | |
x <- readline("What is your choice? ") | |
if(x %in% possibilities == FALSE) {cat("FOOL! That is not one of the options") | |
x<- readline("Try Again: ") | |
} | |
y <- sample(possibilities, 1) | |
z <- which(possibilities==x)-which(possibilities==y) |
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
import difflib | |
import random | |
def name_to_number(x): | |
''' | |
Coverts player choice to number. | |
''' | |
#Uses dict rather than conditionals. | |
my_dict = {'rock':0, 'Spock':1, 'paper':2, 'lizard':3, 'scissors':4} | |
#returns the value associated with the string key | |
return my_dict[x] |
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
def newton_sqrt(x,s=1., kmax=100, tol=1e-8): | |
""" | |
Uses the newton method to approximate square roots. | |
Tolerence set to | |
""" | |
for k in range(kmax): | |
pre_s = s | |
s = .5 * (s + x/s) | |
if abs(s - pre_s) < tol: | |
break |
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(ggplot2); library(MatchIt) | |
meandifftable<- function (x){ | |
post<-data.frame(x$sum.matched[4]) | |
matchID <- as.vector (row.names (post) ) | |
names(post)[1]<-c("m_mean_diff") | |
post$absolute<- abs(post[1]) | |
total2<-post[order (-post$absolute, na.last=NA) ,] | |
meandiffover1<- subset(total2[1], total2[1]> .1 | total2[1]< -.1) | |
meandiffover1 | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Bootstrap 101 Template</title> | |
<!-- The following tag allows for website to be viewed on mobile devices --> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet"> | |
<!-- Bootstrap --> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> |
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
#Custom functions at end of file | |
setwd("/Users/phparker/Dropbox/kaggle/") | |
set.seed(100) | |
library(caret);library(glmnet);library(e1071); library(ROCR) | |
train = read.csv("Higgs/training.csv") | |
train.y = train[,32:33] | |
test = read.csv("Higgs/test.csv") | |
#Will create hold out set when comparing models or now it is fine to use whole set | |
#inTrain <- createDataPartition(train$Label, p = 1/2, list = FALSE) | |
#Re-label missing |
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
require(ggplot2); require(MatchIt) | |
meandifftable<- function (x){ | |
post<-data.frame(x$sum.matched[4]) | |
matchID <- as.vector (row.names (post) ) | |
names(post)[1]<-c("m_mean_diff") | |
post$absolute<- abs(post[1]) | |
total2<-post[order (-post$absolute, na.last=NA) ,] | |
meandiffover1<- subset(total2[1], total2[1]> .1 | total2[1]< -.1) | |
meandiffover1 | |
} |
OlderNewer