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
## | |
# Usage: | |
# python wordle_csv_upload.py /tmp/file.csv | |
## | |
import webbrowser | |
import sys, os | |
filename = sys.argv[1] | |
csv_file = open(filename) |
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
#!/usr/bin/python | |
""" | |
cPickle works well and it is very flexible, but if array only data are available | |
numpy's save features can provide better read speed | |
""" | |
import pickle,os | |
import numpy as np | |
####################################### |
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
''' | |
To run test files, type the following into the terminal | |
py.test file.py –vv | |
''' | |
import unittest as unittest | |
from folder.file import MyClass | |
class TestMyClass(unittest.TestCase): |
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
def flatten_json(y): | |
out = {} | |
def flatten(x, name=''): | |
if type(x) is dict: | |
for a in x: | |
flatten(x[a], name + a + '_') | |
elif type(x) is list: | |
i = 0 | |
for a in x: |
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
import numpy | |
array_2d = np.array([1, 2, 3]).reshape(-1,1) | |
array_2d.shape # (3,1) | |
array_1d = array_2d.flatten() | |
array_1d.shape # (3,) | |
# and from 1d back to 2d... |
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
def precision(y_true, y_pred): | |
i = set(y_true).intersection(y_pred) | |
len1 = len(y_pred) | |
if len1 == 0: | |
return 0 | |
else: | |
return len(i) / len1 | |
def recall(y_true, y_pred): | |
i = set(y_true).intersection(y_pred) |
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
# Normalize Discounted Communicative Gain | |
# NDCG evaluated within list impression for top n items (where NCG is actually ranking and IDCG is the ideal ranking). | |
# Relevance score is generally related to funnel metrics. | |
def dcg(data, n): | |
rel = data['relevance_score'] | |
dcg = sum((rel/np.log2(i + 1)) for i in range(1, n+1)]) | |
return dcg | |
def ndcg(dcg, idcg): |
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
def func(arg1, arg2): | |
"""Summary line. | |
Extended description of function. | |
Parameters | |
---------- | |
arg1 : int | |
Description of arg1 | |
arg2 : str |
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
# https://pypi.org/project/runipy | |
# To save the output of each cell back to the notebook file, run: | |
runipy -o MyNotebook.ipynb | |
# To save the notebook output as a new notebook, run: | |
runipy MyNotebook.ipynb OutputNotebook.ipynb | |
# To run a .ipynb file and generate an HTML report, run: | |
runipy MyNotebook.ipynb --html report.html |
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
Use example code to join all cell values in column A, separated by a comma. | |
=TEXTJOIN(",",TRUE,A:A) |
OlderNewer