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
def model_summary(model, X, y, columns=[]): | |
""" | |
Takes a sklearn model and outputs basic stats, | |
based on input features (X) and target (y) | |
""" | |
import pandas as pd | |
from scipy import stats | |
import numpy as np | |
lm = model | |
params = np.append(lm.intercept_,lm.coef_) |
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 find_term_derivative(term): | |
constant = term[0]*term[1] | |
exponent = term[1] - 1 | |
return (constant, exponent) | |
def find_derivative(function_terms): | |
derivative_terms = list(map(lambda term: find_term_derivative(term),function_terms)) | |
return list(filter(lambda derivative_term: derivative_term[0] != 0, derivative_terms)) |
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
# keras https://keras.io/ | |
from keras.models import Sequential | |
from keras import models | |
from keras import layers | |
from keras import optimizers | |
model = Sequential() | |
model.add(layers.Dense(50, activation='relu', input_shape=(2000,))) | |
model.add(layers.Dense(1, activation='relu')) |
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 nltk.corpus import stopwords | |
stopwords_list = stopwords.words('english') | |
from string import punctuation | |
stopwords_list += list(punctuation) | |
from nltk import word_tokenize | |
tokens = word_tokenize(some_text_data) | |
stopped_tokens = [w.lower() for w in tokens if w not in stopwords_list] |
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 pandas as pd | |
def merge_similar(files=[], encoding=None): | |
""" | |
Concats datasets with similar but not necessarily the same columns | |
by creating empty columns for each dataframe missing a column found in the others | |
""" | |
merged = [] | |
for file in files: | |
df = pd.read_csv(file, encoding=encoding) |
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
def strs_in_float(series): | |
""" | |
Extracts the strings in what would otherwise be a Pandas Series of floats | |
For data cleaning. | |
""" | |
def is_float(x): | |
try: | |
float(x) | |
return False | |
except: |
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
Python | |
from sklearn import datasets | |
import seaborn as sn | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from sklearn.manifold import TSNE | |
#import the digits dataset | |
digits = datasets.load_digits() |
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
def multivariateGaussian(X, mu, sigma): | |
k = len(mu) | |
sigma=np.diag(sigma) | |
X = X - mu.T | |
p = 1/((2*np.pi)**(k/2)*(np.linalg.det(sigma)**0.5))* np.exp(-0.5* np.sum(X @ np.linalg.pinv(sigma) * X,axis=1)) | |
return p | |
p = multivariateGaussian(X, mu, sigma) |
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 | |
class LPSolution(object): | |
def __init__(self): | |
self.iterations = None | |
self.tolerance = None | |
self.intermediates = [] | |
self.solution = None | |
self.solution_string = None |
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
#!/usr/bin/env python | |
import fileinput | |
import csv | |
import sys | |
#https://github.com/jamesmishra/mysqldump-to-csv | |
# This prevents prematurely closed pipes from raising | |
# an exception in Python | |
from signal import signal, SIGPIPE, SIG_DFL |