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
| select | |
| communityID | |
| ,min(date) as join_date | |
| ,max(date) as leave_date | |
| ,count(*) as duration | |
| from history | |
| where accountID = 'shawlu' | |
| group by communityID; |
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
| select date, count(accountID) as size | |
| from history | |
| where communityID = 10 | |
| group by date | |
| order by date; |
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
| 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] |
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
| 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) |
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 | |
| 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 |
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
| // objective C | |
| if (@available(iOS 13.0, *)) { | |
| cell.backgroundColor = [UIColor systemBackgroundColor]; | |
| } else { | |
| cell.backgroundColor = [UIColor whiteColor]; | |
| } |
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 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() |
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 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] |
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
| pip install pandas py2neo |
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
| 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 |
NewerOlder