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
WITH RECURSIVE NetworkCTE AS ( | |
-- Anchor part to select the starting node | |
SELECT source_node, | |
target_node | |
FROM network_connections | |
WHERE source_node = 'Paolo' -- Change this to get someone else's network | |
UNION ALL | |
-- Recursive part to select connected nodes |
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 bayesian_liklihood(df, target_col, target_val, prior_col): | |
""" | |
Gets the liklihood of a target value given a prior value using Bayesian formula | |
on a Pandas dataframe | |
df: Pandas dataframe | |
target_col: column being predicted | |
target_val: value in the target_col being predicted | |
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 Function ## | |
from numpy import array, random, arange | |
def xicor(X, Y, ties=True): | |
random.seed(42) | |
n = len(X) | |
order = array([i[0] for i in sorted(enumerate(X), key=lambda x: x[1])]) | |
if ties: | |
l = array([sum(y >= Y[order]) for y in Y[order]]) | |
r = l.copy() |
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 scipy.special import loggamma | |
from scipy.special import expit, logit | |
import numpy as np | |
from scipy.optimize import minimize | |
def logLikelihood(params, y, X): | |
b = np.array(params[0:-1]) # the beta parameters of the regression model | |
phi = params[-1] # the phi parameter | |
mu = expit(np.dot(X,b)) |
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 | |
neg = model.theta_[0].argsort() | |
print(np.take(X_test.columns, neg[:10])) | |
print('') | |
neg = model.sigma_[0].argsort() | |
print(np.take(X_test.columns, neg[:10])) |
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
# Extends USPS api class to calculate time for Standard delivery from zip to zzip | |
from lxml import etree | |
def get_time(origin_zip, dest_zip): | |
usps = USPSApi(USPS_API_USER, test=True) | |
#usps.urls['calc'] = 'PriorityMail&XML={xml}' | |
usps.urls['calc'] = 'StandardB&XML={xml}' |
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 typing import Optional, Union | |
import numpy as np | |
import pandas as pd | |
from sklearn.linear_model import LinearRegression, LogisticRegression | |
from sklearn.base import BaseEstimator | |
from sklearn.utils.estimator_checks import check_estimator | |
from sklearn.utils.validation import check_X_y, check_array, check_is_fitted | |
from lightgbm import LGBMClassifier, LGBMRegressor |
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 |
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
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) |
NewerOlder