Skip to content

Instantly share code, notes, and snippets.

View ryanholbrook's full-sized avatar

Ryan Holbrook ryanholbrook

View GitHub Profile
@ryanholbrook
ryanholbrook / find_duplicate_images.py
Last active October 13, 2021 14:44
Detect Duplicate Images
from joblib import delayed, Parallel
from pathlib import Path
from tqdm import tqdm
import hashlib
import imagehash
import pandas as pd
import PIL
import pybktree
from PIL import Image
@ryanholbrook
ryanholbrook / forecasting_metrics.py
Last active May 12, 2021 13:31 — forked from bshishov/forecasting_metrics.py
Python Numpy functions for most common forecasting metrics
import numpy as np
EPSILON = 1e-10
def _error(actual: np.ndarray, predicted: np.ndarray):
""" Simple error """
return actual - predicted
=
# +
import numpy as np
import matplotlib.pyplot as plt
plt.style.use("seaborn-whitegrid")
plt.rc('figure', autolayout=True)
plt.rc('axes',
labelweight='bold',
labelsize='large',
@ryanholbrook
ryanholbrook / schedule.py
Created May 1, 2021 12:28
Keras Optax Schedules
import tensorflow as tf
import tensorflow.experimental.numpy as tnp
from absl import logging
from typing import Callable, Dict, Union, Optional, Iterable, Sequence
from tensorflow import keras
from tensorflow.keras.optimizers.schedules import LearningRateSchedule
# Schedules ported from Optax
# https://github.com/deepmind/optax/blob/master/optax/_src/schedule.py
@ryanholbrook
ryanholbrook / optvis.py
Created January 9, 2021 14:15
Optimization Visualization
import math
from itertools import product
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import tensorflow.keras as keras
from matplotlib import gridspec
# # Activation Model #
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import matplotlib.pyplot as plt
from matplotlib import animation, rc
rc('animation', html='html5')
plt.style.use('seaborn-whitegrid')
@ryanholbrook
ryanholbrook / decision_boundary.org
Created January 18, 2020 13:45
R code for plotting and animating the decision boundaries

Classifiers

Introduction

Looking at the decision boundary a classifier generates can give us some geometric intuition about the decision rule a classifier uses and how this decision rule changes as the classifier is trained on more data.

Plotting Functions

@ryanholbrook
ryanholbrook / convex_aggregation.R
Created October 3, 2019 08:18
Convex Dirichlet Aggregation with brms and Parsnip
library(brms)
library(parsnip)
## Fits a brms model
convex_regression <- function(formula, data,
family = "gaussian",
alpha = 1, gamma = 2, # Yang (2014) recommends alpha=1, gamma=2
verbose = 0,
...) {
if (gamma <= 1) {