{{ message }}

Instantly share code, notes, and snippets.

# Garrett Bushnell gbushnell

Created Oct 15, 2020
Query Invoices for RFM Analysis
View invoice_pull.sql
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
 SELECT IV.client__description as "client_description", IV.invoice_date, IV.amount FROM Invoice_View IV
Created Oct 1, 2020
View benfords_ci.py
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
 # Calculate Confidence Intervals for probability matrix def calc_confidence_interval(alpha): alpha_stat = stats.norm.ppf(1 - (1 - alpha) / 2) for d_i in range(expected_prob_matrix.shape[0]): for n_i in range(expected_prob_matrix.shape[1]): prop_exp = expected_prob_matrix[d_i, n_i] half_length = alpha_stat * (prop_exp * (1 - prop_exp) / data_cols_length[n_i]) ** .5 + ( 1 / (2 * data_cols_length[n_i])) u_bound = prop_exp + half_length
Last active Oct 1, 2020
Expected Frequency of digit occurrences in leading 2 digits per Benford's Law
View benfords_law_expected.py
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
 # Probability of digit (d) occurring in nth position def calc_expected_probability(d: int, n: int) -> float: # generalization of Benford's Law ~ Summation( log[ 1 + (1/(10k+d)] ) where d = digit, k = (10^(n-2), 10^(n-1)) # source: https://en.wikipedia.org/wiki/Benford%27s_law prob = 0 if (d == 0) and (n == 1): prob = 0 elif n == 1: prob = math.log10(1 + (1 / d)) else: