Skip to content

Instantly share code, notes, and snippets.

Tim Hoolihan thoolihan

View GitHub Profile
@thoolihan
thoolihan / run_tb.sh
Created Jul 13, 2018
Run tensorboard
View run_tb.sh
tensorboard --logdir /tmp/myproject --host 0.0.0.0
@thoolihan
thoolihan / tensorboard_callback_example.py
Created Jul 13, 2018
Example of tensorboard callback
View tensorboard_callback_example.py
from shared.get_start_time get_start_time, get_curr_time
# the tensorboard log directory will be a unique subdirectory based on the start time fo the run
TBLOGDIR="/tmp/myproject/{}".format(get_start_time())
# ...your model code here...
history = model.fit(train_images,
train_images,
epochs=EPOCHS,
@thoolihan
thoolihan / get_start_time.py
Created Jul 13, 2018
python consistent start time
View get_start_time.py
from datetime import datetime
def get_curr_time():
return datetime.now().strftime("%Y.%m.%d.%H.%M.%S")
def get_start_time():
return _start_time if _start_time else get_curr_time()
_start_time = get_start_time()
@thoolihan
thoolihan / nba.R
Last active May 23, 2018
Graphing Sports Odds
View nba.R
library(ggplot2)
library(dplyr)
library(R.utils)
teams <- data.frame(team = c('warriors', 'rockets',
'cavaliers', 'celtics'),
odds_nw = c(5,9,8,20),
odds_w = c(9,4,1,1))
# raw probabilities sum to more than 1 because of house take
View target_encode.py
import numpy as np
import pandas as pd
from sklearn.base import BaseEstimator, TransformerMixin
# Adapted from https://www.kaggle.com/ogrellier/python-target-encoding-for-categorical-features
class TargetEncoder(BaseEstimator, TransformerMixin):
def __init__(self, columns, noise_level = 0):
self.columns = columns
self.maps = {}
View gist:06d2d93d2618fd6535ffedaa40f33bff
> df <- data.frame(date = c('2017-10-01', '2017-10-11'))
> df$date <- as.Date(df$date)
> df
date
1 2017-10-01
2 2017-10-11
> sapply(df$date, function(d) {if (d < as.Date('2017-10-07')) 1 else 0})
[1] 1 0
> df$week1 <- sapply(df$date, function(d) {if (d < as.Date('2017-10-07')) 1 else 0})
> df
@thoolihan
thoolihan / arrange_plot.R
Last active Aug 3, 2017
arrange and plot not working together
View arrange_plot.R
library(tidyverse)
mtcars %>%
mutate(car = rownames(.)) %>%
arrange(hp) %>%
ggplot(aes(x = car, y = hp)) +
geom_point() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
@thoolihan
thoolihan / mc.R
Created Jun 30, 2017
Simulate 2 state Markov Chain from Wikipedia
View mc.R
# simulating https://en.wikipedia.org/wiki/Markov_chain#/media/File:Markovkate_01.svg
library(ggplot2)
means = c()
ntimes <- 1000
for (t in 1:ntimes) {
n <- 1000
state <- c(1)
@thoolihan
thoolihan / distance.R
Last active Mar 30, 2017
color distance
View distance.R
library(dplyr)
n <- 1000000
data <- data.frame(id = 1:n,
red = sample(0:255, size = n, replace = TRUE),
green = sample(0:255, size = n, replace = TRUE),
blue = sample(255, size = n, replace = TRUE))
query <- list(red = 80, green = 90, blue = 255)
@thoolihan
thoolihan / monty_hall.R
Last active Mar 22, 2017
Simulation of the famous Monty Hall problem in R
View monty_hall.R
library(dplyr)
library(ggplot2)
doors <- 1:3
sample_doors <- function() { return(sample(doors, size = 1000, replace = TRUE))}
games <- data.frame(prize = sample_doors(), pick = sample_doors())
games$strategy <- factor(ifelse(games$prize == games$pick, 'stay', 'switch'))
monte_show <- function(prize, pick) {
You can’t perform that action at this time.