Based on http://sox.sourceforge.net/sox.html
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
# https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/ | |
import sys | |
!{sys.executable} -m pip install <package> |
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 IPython.core.magic import register_cell_magic | |
import datetime | |
@register_cell_magic | |
def log_error(line, cell): | |
try: | |
exec(cell) | |
except Exception as e: | |
with open('error.log', 'w+') as f: | |
f.write("[{}] Exception ({}): {}".format(datetime.datetime.now(), |
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 re | |
def remove_comments(s): | |
for x in re.findall(r'("[^\n]*"(?!\\))|(//[^\n]*$|/(?!\\)\*[\s\S]*?\*(?!\\)/)',s,8):s=s.replace(x[1],'') | |
s = re.sub(r'(?m) *#.*\n?', '', s) | |
return s |
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 subprocess | |
from collections import OrderedDict | |
from collections import Iterable | |
import six | |
import time | |
import numpy as np | |
from keras.callbacks import Callback |
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
find folder -type f -name "*.txt" -exec wc -L {} \; | cut -f 1 -d ' ' awk '{{ total+=$NF }} END {{ print total/NR }}' |
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 sklearn.metrics import classification_report | |
from sklearn.metrics import confusion_matrix | |
import pandas as pd | |
def evalutate_metrics(clf, X_test, y_test, threshold=0.5): | |
y_pred = clf.predict(X_test)[:,1] | |
y_test_l = np.argmax(y_test, axis=1) | |
print() | |
print('Confusion matrix:') | |
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
curl -s http://php.net/manual/en/indexes.functions.php | grep -o 'class="index">.*</a>' | sed 's/\(class="index">\|<\/a>\)//g' |
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 pandas as pd | |
def days_generator(start_date, end=pd.Timestamp.today(), step_day=1, format='%Y-%m-%d'): | |
""" | |
Generate a dates in a format from start_date to end | |
with a step of step_day | |
""" | |
s = pd.to_datetime(start_date) | |
while s <= end: | |
yield s.strftime(format) |
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 sklearn import metrics | |
fpr, tpr, thresholds = metrics.roc_curve(y_test, y_pred_raw) | |
# Just finding point closest to [0,1] | |
max_indice = np.argmin([((ft[0])**2 + (ft[1]-1)**2) for ft in (zip(fpr, tpr))]) | |
threshold = thresholds[max_indice] | |
# We can display it on the ROC curve | |
fig = plt.figure() | |
plt.plot(fpr,tpr) |
NewerOlder