Skip to content

Instantly share code, notes, and snippets.

View shawlu95's full-sized avatar

Shaw Lu shawlu95

View GitHub Profile
@shawlu95
shawlu95 / 10_account_hist.sql
Created November 18, 2019 09:02
10_comm_track
select
communityID
,min(date) as join_date
,max(date) as leave_date
,count(*) as duration
from history
where accountID = 'shawlu'
group by communityID;
@shawlu95
shawlu95 / 10_comm_size.sql
Created November 18, 2019 08:59
10_comm_track
select date, count(accountID) as size
from history
where communityID = 10
group by date
order by date;
@shawlu95
shawlu95 / 9_credible_conf.py
Last active November 9, 2019 21:52
9_credible_conf
p_hat = heads / n
se = np.sqrt(p_hat * (1 - p_hat) / n)
f_up = p_hat + 1.96 * se
f_lo = p_hat - 1.96 * se
print("95%% confidence interval: [%.3f, %.3f]"%(f_lo, f_up))
# 95% confidence interval: [0.416, 0.984]
@shawlu95
shawlu95 / 9_credible_plot.py
Last active November 9, 2019 22:45
9_credible_plot
prior_a = 1
prior_b = 1
a = prior_a + heads
b = prior_b + tails
rv = beta(a, b)
x = np.linspace(0, 1, 100)
b_up = btdtri(a, b, 0.95)
@shawlu95
shawlu95 / 9_credible_trial.py
Last active November 9, 2019 21:47
9_credible_trial
import numpy as np
from scipy.stats import beta, t, norm
from scipy.special import btdtri
import matplotlib.pyplot as plt
p = 0.5
n = 10
success = np.random.binomial(p=p, n=n)
failure = n - success
@shawlu95
shawlu95 / 08_version_check.m
Created September 29, 2019 20:03
08_version_check.m
// objective C
if (@available(iOS 13.0, *)) {
cell.backgroundColor = [UIColor systemBackgroundColor];
} else {
cell.backgroundColor = [UIColor whiteColor];
}
@shawlu95
shawlu95 / 07_find_path.py
Last active September 18, 2019 05:27
Chinese idiom graph blog
def find_path(idiom, length, limit):
cql = "match ()-[e:idiom {idiom: '%s'}]->()"%idiom
path = "".join(["-[e%i:idiom]->()"%(i + 1) for i in range(length)])
ret = ", ".join(["e%i.idiom as i%i"%(i + 1, i + 1) for i in range(length)])
query = cql + path + " return e.idiom as i0, " + ret + " limit %i"%limit
return graph.run(query).to_data_frame()
@shawlu95
shawlu95 / 07_load_database.py
Created September 17, 2019 23:01
Chinese idiom graph blog
from py2neo import Graph
graph = Graph("bolt://localhost:7687", password="12345678")
# Parse the source
with open('dataset/THUOCL_chengyu.txt', 'r', encoding='utf-8') as source:
idioms = [i for i in map(lambda x: x.split()[0], source.readlines()) if len(i) <= 4]
nodes = set([i[0] for i in idioms] + [i[-1] for i in idioms])
edges = [{"src": i[0], "dst": i[-1], "idiom": i} for i in idioms]
@shawlu95
shawlu95 / 07_pip_install.sh
Created September 17, 2019 22:58
Chinese idiom graph blog
pip install pandas py2neo
@shawlu95
shawlu95 / 05_sql_feature_engineering_pull.py
Last active April 9, 2019 21:23
05_sql_feature_engineering
X_trn, Y_trn = load_dataset("trn_set", limit=5)
print(X_trn.head().T)
# 0 1 2 3 4
# category 1 1 1 1 1
# event1 0 0 0 0 0
# order_count 1 2 2 1 1
# revenue_sum 30.49 191.33 191.33 76.96 66.77
# revenue_max 30.49 98.38 98.38 76.96 66.77