Skip to content

Instantly share code, notes, and snippets.

View benjaminirving's full-sized avatar

Benjamin Irving benjaminirving

View GitHub Profile
@maidens
maidens / sensitivity_specificity_confidence_intervals.py
Created May 14, 2018 18:28
Confidence intervals for sensitivity and specificity in Python
from __future__ import print_function, division
from math import sqrt
from scipy.special import ndtri
def _proportion_confidence_interval(r, n, z):
"""Compute confidence interval for a proportion.
Follows notation described on pages 46--47 of [1].
@samoshkin
samoshkin / toggle_keybindings.tmux.conf
Last active February 5, 2024 02:26
tmux.conf excerpt to toggle on/off session keybindings and prefix handling
bind -T root F12 \
set prefix None \;\
set key-table off \;\
set status-style "fg=$color_status_text,bg=$color_window_off_status_bg" \;\
set window-status-current-format "#[fg=$color_window_off_status_bg,bg=$color_window_off_status_current_bg]$separator_powerline_right#[default] #I:#W# #[fg=$color_window_off_status_current_bg,bg=$color_window_off_status_bg]$separator_powerline_right#[default]" \;\
set window-status-current-style "fg=$color_dark,bold,bg=$color_window_off_status_current_bg" \;\
if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
refresh-client -S \;\
bind -T off F12 \
@fsausset
fsausset / keras2android.py
Created March 31, 2017 14:43
Export a Keras model to a tensorflow .pb file with embedded weights to use on Android.
from keras.models import Sequential
from keras.models import model_from_json
from keras import backend as K
import tensorflow as tf
from tensorflow.python.tools import freeze_graph
import os
# Load existing model.
with open("model.json",'r') as f:
modelJSON = f.read()
@simonkamronn
simonkamronn / bland_altman.py
Created March 1, 2017 16:25
Bland-Altman plot in Bokeh with vertical histogram and normal fit on the right y-axis
from scipy.stats import norm, shapiro, kstest, anderson
import bokeh.plotting as bplt
from bokeh import layouts
from bokeh.charts import Histogram, Scatter
from bokeh.models import Span
import pandas as pd
import numpy as np
def vertical_histogram(y):
@wrwrwr
wrwrwr / lambda.sh
Created February 15, 2017 23:32
Package a Python module with NumPy and SciPy for AWS Lambda.
#!/usr/bin/env bash
# Path to the project directory (that should include requirements.txt),
# Files and directories within that need to be deployed.
project=../backend
contents=(module lamdba_handler.py)
# Unnecessary parts. Note that there are some inter-dependencies in SciPy,
# for example to use scipy.stats you also need scipy.linalg, scipy.integrate,
# scipy.misc, scipy.sparse, and scipy.special.
@wassname
wassname / keras_weighted_categorical_crossentropy.py
Last active December 19, 2023 18:17
Keras weighted categorical_crossentropy (please read comments for updated version)
"""
A weighted version of categorical_crossentropy for keras (2.0.6). This lets you apply a weight to unbalanced classes.
@url: https://gist.github.com/wassname/ce364fddfc8a025bfab4348cf5de852d
@author: wassname
"""
from keras import backend as K
def weighted_categorical_crossentropy(weights):
"""
A weighted version of keras.objectives.categorical_crossentropy
@juanpabloaj
juanpabloaj / README.md
Last active June 18, 2018 13:02
Total of pip packages downloaded, separated by Python versions

Total of pip packages downloaded separated by Python versions

From June 26, 2016 (python 3.5.2 release) to Aug. 31, 2016.

Python versions from 2.6 to 3.5

downloads_by_versions

Without 2.7

@fchollet
fchollet / classifier_from_little_data_script_2.py
Last active September 13, 2023 03:34
Updated to the Keras 2.0 API.
'''This script goes along the blog post
"Building powerful image classification models using very little data"
from blog.keras.io.
It uses data that can be downloaded at:
https://www.kaggle.com/c/dogs-vs-cats/data
In our setup, we:
- created a data/ folder
- created train/ and validation/ subfolders inside data/
- created cats/ and dogs/ subfolders inside train/ and validation/
- put the cat pictures index 0-999 in data/train/cats
@fchollet
fchollet / classifier_from_little_data_script_1.py
Last active November 28, 2023 07:12
Updated to the Keras 2.0 API.
'''This script goes along the blog post
"Building powerful image classification models using very little data"
from blog.keras.io.
It uses data that can be downloaded at:
https://www.kaggle.com/c/dogs-vs-cats/data
In our setup, we:
- created a data/ folder
- created train/ and validation/ subfolders inside data/
- created cats/ and dogs/ subfolders inside train/ and validation/
- put the cat pictures index 0-999 in data/train/cats
@saliksyed
saliksyed / autoencoder.py
Created November 18, 2015 03:30
Tensorflow Auto-Encoder Implementation
""" Deep Auto-Encoder implementation
An auto-encoder works as follows:
Data of dimension k is reduced to a lower dimension j using a matrix multiplication:
softmax(W*x + b) = x'
where W is matrix from R^k --> R^j
A reconstruction matrix W' maps back from R^j --> R^k