This file contains hidden or 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
| # Code for: | |
| # https://stats.stackexchange.com/questions/360863/probability-based-on-observed-data/360892#360892 | |
| set.seed(123) | |
| A <- c(34.5, 34.2, 35, 35.1, 36, 35.2, 35.7, 34.8, 34.9, 34.4) | |
| B <- c(35, 34.2, 36, 35, 34, 34.2, 34.2, 34.5, 34.4) | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 tqdm import tqdm | |
| def tqdm_function_decorator(*args, **kwargs): | |
| """ | |
| Decorate a function by adding a progress bar | |
| Parameters | |
| ---------- | |
| *args, **kwargs |
This file contains hidden or 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 __future__ import absolute_import | |
| from __future__ import division | |
| from __future__ import print_function | |
| from six import iteritems | |
| from tqdm import tqdm | |
| from collections import Counter | |
| import re | |
| class TopKTokenizer(object): |
This file contains hidden or 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
| # Many of the functions are adapted from: | |
| # https://www.polydesmida.info/cookbook/functions.html | |
| nohead () | |
| { | |
| if [[ $# -eq 0 || "$1" == "-h" ]] ; then | |
| echo "Useage: nohead file [n=1]" | |
| echo "Omit header (n rows) from a file." |
This file contains hidden or 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 xxhash | |
| from keras.preprocessing.text import hashing_trick | |
| # one_hot and hashing_trick in Keras both use by default python's hash function | |
| # it is unstable: https://stackoverflow.com/q/27522626/3986320 | |
| # alternatively, you could use md5, but it's not the fastest hashing function | |
| # xxHash package offers a faster alternative | |
| xxh = lambda w: int(xxhash.xxh32(w.encode()).hexdigest(), 16) | |
| one_hot = lambda x, n, **kwargs: hashing_trick(x, n, hash_function=xxh, **kwargs) |
This file contains hidden or 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 keras.callbacks import Callback | |
| import matplotlib.pyplot as plt | |
| class LRFinder(Callback): | |
| ''' | |
| A simple callback for finding the optimal learning rate range for your model + dataset. | |
| # Usage | |
| ```python |
This file contains hidden or 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 keras import backend as K | |
| from keras.layers import Average | |
| from keras.activations import softmax | |
| class WeightedAverage(Average): | |
| def build(self, input_shape): | |
| self.kernel = self.add_weight(name='kernel', | |
| shape=(1, len(input_shape)), | |
| initializer='ones', |
This file contains hidden or 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 numpy as np | |
| def train_test_split(*arrays, test_size, random_state, clusters): | |
| '''Split to train and test samples by clusters | |
| Parameters | |
| ---------- | |
| test_size : float, 0 < test_size < 1 | |
| fraction of clusters to include in test set |
This file contains hidden or 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 numpy as np | |
| from sklearn.metrics import roc_curve | |
| def sensivity_specifity_cutoff(y_true, y_score): | |
| '''Find data-driven cut-off for classification | |
| Cut-off is determied using Youden's index defined as sensitivity + specificity - 1. | |
| Parameters | |
| ---------- |