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
import pandas as pd | |
import numpy as np | |
def bin_data(dataframe, field, num_bins): | |
bins = np.linspace(df[field].min(), df[field].max(), num_bins) | |
dataframe[field+'_Bins'] = pd.cut(dataframe[field], bins) | |
return dataframe | |
if __name__ == "__main__": | |
df = pd.DataFrame(np.random.uniform(0, 100, size=(100, 3))) |
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
import pandas as pd | |
import numpy as np | |
def is_outlier(value, p25, p75): | |
"""Check if value is an outlier | |
""" | |
lower = p25 - 1.5 * (p75 - p25) | |
upper = p75 + 1.5 * (p75 - p25) | |
return value <= lower or value >= upper |
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
import tensorflow as tf | |
import pandas as pd | |
import numpy as np | |
from tqdm import tqdm | |
import os | |
def _int64_feature(value): | |
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) |
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
import tensorflow as tf | |
import pandas as pd | |
import numpy as np | |
import os | |
from tqdm import tqdm | |
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
from PIL import Image, ImageOps | |
import PIL |
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
import pandas as pd | |
import numpy as np | |
import time | |
import random | |
''' | |
This class will return a random time series based window of data. It intakes a dataframe | |
that is already pre sorted into the correct time pattern where index 0 is timestep 0 | |
and index N is timestep N. The function window_maker will incrementally step through | |
the entire dataframe returning the next window of data. The function random_window_maker |
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 text_class_encoder(df): | |
dtypes = pd.DataFrame(df.dtypes) | |
text_cols = list(dtypes[dtypes.iloc[:,0] == 'object'].index) | |
label_encoder_dict = {} | |
for col in text_cols: | |
label_encoder_dict[col] = LabelEncoder() | |
label_encoder_dict[col].fit(df[col]) | |
df[col] = label_encoder_dict[col].transform(df[col]) | |
return df, label_encoder_dict |
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
import numpy as np | |
class batcher(object): | |
def __init__(self, data, batch_size, target=None): | |
self.data = data | |
self.batch_size = batch_size | |
self.batch_n = 0 | |
self.n_batches =int(data.shape[0]/batch_size) | |
self.target = target | |
if target != None: |
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
import scipy.io as spio | |
def loadmat(filename): | |
''' | |
this function should be called instead of direct spio.loadmat | |
as it cures the problem of not properly recovering python dictionaries | |
from mat files. It calls the function check keys to cure all entries | |
which are still mat-objects | |
''' |
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
import numpy as np | |
import tensorflow as tf | |
from tensorflow.examples.tutorials.mnist import input_data | |
from sklearn import datasets | |
from sklearn.mixture import GaussianMixture | |
from sklearn.model_selection import StratifiedKFold | |
#%matplotlib qt | |
from sklearn.cluster import KMeans | |
import numpy as np | |
from sklearn.manifold import TSNE |
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.manifold import TSNE | |
from mpl_toolkits.mplot3d import Axes3D | |
%matplotlib qt | |
from IPython import display | |
import matplotlib.cm as cmx | |
import matplotlib.colors as colors | |
def get_cmap(N): | |
'''Returns a function that maps each index in 0, 1, ... N-1 to a distinct | |
RGB color.''' |
OlderNewer