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
#!/bin/bash | |
# conda-install.sh [~/miniconda3] [miniconda.sh] | |
# | |
# First argument is the install folder. Defaults to ~/miniconda3 | |
# Second argument is the install script (downloaded if not found.) | |
# No getopts here: to use second arg have to use first arg | |
INSTALL_DIR=${1:-$HOME/miniconda3} | |
INSTALL_SCRIPT=${2:-miniconda.sh} |
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 __future__ import print_function | |
import matplotlib.pyplot as plt | |
from matplotlib.path import Path | |
from matplotlib.spines import Spine | |
from matplotlib.projections.polar import PolarAxes | |
from matplotlib.projections import register_projection | |
import numpy as np | |
def radar_plot(data, axes=[], colors=[], labels=[], ax=None, frame='circle', **kwargs): | |
'''Create radar plot from 2D array. Each row is a closed line; each column is a feature/axis. |
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 sklearn.base import BaseEstimator,TransformerMixin | |
class LogTransformer(BaseEstimator,TransformerMixin): | |
def __init__(self, constant=1, base='e'): | |
from numpy import log,log10 | |
if base == 'e' or base == np.e: | |
self.log = log | |
elif base == '10' or base == 10: | |
self.log = log10 | |
else: |
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
#!/usr/bin/env python | |
"""Docstring | |
""" | |
def main(args=None): | |
# Pipe into head/tail w/o IOErrors | |
from signal import signal, SIGPIPE, SIG_DFL | |
signal(SIGPIPE,SIG_DFL) | |
parsed_args = _parse_args(args) |
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 by_n(iterable, n=2): | |
"""Return an sliding window iterable of tuples of size `n` | |
E.g. | |
>>> w = by_n(range(10), n=2) | |
>>> next(w) | |
(0,1) | |
>>> next(w) | |
(1,2) | |
""" |
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
%load_ext autoreload | |
%autoreload 1 | |
%matplotlib inline | |
%config InlineBackend.figure_format='retina' | |
from __future__ import division, print_function | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns |
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 arrays_equal_nan(a, b): | |
'Arrays compare True if they are equal or both NaN, else False' | |
return np.all((a==b) | ((a!=a) & (b!=b))) |
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
#!/usr/bin/env python | |
# Install a matplotlib style file | |
from __future__ import print_function | |
import matplotlib | |
from matplotlib import style as mplstyle | |
import os | |
import sys | |
import shutil | |
import argparse | |
import requests |
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 sklearn.feature_extraction import DictVectorizer | |
class DataFrameVectorizer(DictVectorizer): | |
'''Scikit-learn transformer for DataFrames. Categorical features become one-hot encoded. | |
>>> df = pd.DataFrame({'school': ['a','b','c'], 'gpa': [2,3,4]}) | |
>>> dv = DataFrameVectorizer() | |
>>> transformed = dv.fit_transform(df) | |
>>> dv.inverse_transform(transformed) |
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 pyspark.sql import DataFrame | |
from functools import wraps | |
import hashlib | |
from os import path, remove | |
import logging | |
from sys import stderr | |
def getLogger(name, debug=False, loglevel=None): | |
logger = logging.getLogger(name) | |
if not logger.handlers: |
OlderNewer