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 insertion_sort(a): | |
''' implement insertion sort''' | |
for i in xrange(1, len(a)): | |
key = a[i] | |
j = i - 1 | |
while j >= 0: | |
if a[j] > key: | |
a[j], a[j+1] = a[j + 1], a[j] | |
j = j - 1 | |
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
from scipy.stats import beta | |
def binom_interval(success, total, confint=0.95): | |
quantile = (1 - confint) / 2. | |
lower = beta.ppf(quantile, success, total - success + 1) | |
upper = beta.ppf(1 - quantile, success + 1, total - success) | |
return (lower, upper) |
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
# coding: utf-8 | |
""" Create a scatter-plot matrix using Matplotlib. """ | |
from __future__ import division, print_function | |
__author__ = "adrn <[email protected]>" | |
# Standard library | |
import os, sys |
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
# This Python application will calculate the passer rating | |
# (passer efficiency or pass efficiency) given the five required variables. | |
# | |
# Variables to be used as values are defined below. Set to strings so input | |
# can be anything. Later the strings will be converted to numbers, given | |
# they pass a series of error checking tests. | |
COMP = "null" | |
ATT = "null" | |
YARDS = "null" |
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
## Warren Buffet's 1B Basketball Challenge ## | |
expected_value <- function(p,ngames=63,prize=1000000000){ | |
p^ngames * prize | |
} | |
## What is the expected value of an entry | |
## given a particular level of prediction accuracy | |
expected_value(p=0.80) | |
expected_value(p=0.85) |
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
getBREFTeamStatTable <- | |
function(season_end = 2015, table_name = 'team', date = T) { | |
packages <- | |
c('rvest','dplyr','pipeR','RCurl', 'XML','reshape2', 'tidyr', 'magrittr') | |
lapply(packages, library, character.only = T) | |
base <- | |
'http://www.basketball-reference.com/leagues/' | |
season <- | |
(season_end - 1) %>% | |
paste0("-",season_end) |
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 Basketball Reference Scraper Season Scraper | |
get_bref_player_season_stats <- | |
function(season.end, stat_type = c("Advanced","Totals","Per Minute","Per Game"), | |
team.totals = F , league = 'NBA'){ | |
packages <- | |
c('rvest','magrittr','dplyr','stringr','tidyr') | |
lapply(packages, library, character.only = T) | |
bref_team_base <- | |
'http://www.basketball-reference.com/leagues/' |
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
source( | |
"https://gist.githubusercontent.com/abresler/bc5c6d8753bac661415e/raw/a9cde8afae83777f4fa32d1ac978e843f8398ee0/nba_player_data.r" | |
) | |
devtools::install_github('cmpolis/datacomb', subdir = 'pkg') | |
packages <- | |
c('datacomb', 'dplyr', 'htmlwidgets', 'magrittr') | |
lapply(packages, library, character.only = T) | |
data <- | |
get_bref_season_player_stats( |
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(twitteR) | |
require(devtools) | |
install_github('rCharts', 'ramnathv') ## install rCharts | |
require(data.table) | |
#Register Twitter | |
## A real example, but using a fictitious consumerkey and consumer | |
## secret - you'll need to supply your own | |
#register access to twitter API |
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(dplyr) | |
library(tidyr) | |
library(magrittr) | |
library(ggplot2) | |
"http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYNEWYOR.txt" %>% | |
read.table() %>% data.frame %>% tbl_df -> data | |
names(data) <- c("month", "day", "year", "temp") | |
data %>% | |
group_by(year, month) %>% |
OlderNewer