Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf8
from collections import defaultdict
import gzip
def get_graph_stamps(path, top=None):
count = defaultdict(int)
srcs = set()
with gzip.open(path, 'r') as in_file:
#-*- coding: utf8
from hyperopt import fmin
from hyperopt import hp
from hyperopt import tpe
from tick.hawkes import HawkesADM4
from tick.hawkes import HawkesCumulantMatching
from tick.hawkes import HawkesSumGaussians
#-*- coding: utf8
from hyperopt import fmin
from hyperopt import hp
from hyperopt import tpe
from tick.hawkes import HawkesADM4
from tick.hawkes import HawkesCumulantMatching
from tick.hawkes import HawkesSumGaussians
def precision10(A_true, A_pred, k=10):
res = 0.0
tmp = 0
for i in range(A_true.shape[0]):
x = set(A_true[i].argsort()[::-1][:k])
y = set(A_pred[i].argsort()[::-1][:k])
res += len(x.intersection(y)) / len(x)
tmp += 1
return res / tmp
@flaviovdf
flaviovdf / gist:e9df56b7ba9e44f75cb8d5e29f7a6173
Created April 23, 2016 12:48
du sort directory never forget
du -h --summarize .[!.]* * | sort -h
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
@flaviovdf
flaviovdf / felipe_test.py
Created June 10, 2013 22:42
Learning mod 2 (xor) using binary representation
from sklearn import grid_search
from sklearn import metrics
from sklearn import tree
import numpy as np
def create_sample_decimal(num_rows, max_val):
X = np.random.randint(0, max_val, size=(num_rows, 2))
y = (X[:, 0] + X[:, 1]) % 2
@flaviovdf
flaviovdf / gist:5546884
Created May 9, 2013 11:07
tabs to spaces
#recommend running on source folders and not project folder.
find ./ -type f \( ! -regex '.*/\..*' \) -exec sed -i 's/\t/ /g' {} \;
@flaviovdf
flaviovdf / gist:4174938
Created November 30, 2012 10:12
http headers tshark
sudo tshark -i eth0 -f 'port 80 or 443' -R 'http.host matches ".*?youtube\.com.*"' -S -V -l -T fields -e ip.src -e ip.src_host -e ip.dst -e ip.dst_host -e http.accept -e http.accept_encoding -e http.accept_language -e http.authbasic -e http.authorization -e http.cache_control -e http.connection -e http.content_encoding -e http.content_length -e http.content_length_header -e http.content_type -e http.cookie -e http.date -e http.host -e http.last_modified -e http.location -e http.notification -e http.proxy_authenticate -e http.proxy_authorization -e http.proxy_connect_host -e http.proxy_connect_port -e http.referer -e http.request -e http.request.full_uri -e http.request.method -e http.request.uri -e http.request.version -e http.response -e http.response.code -e http.response.phrase -e http.sec_websocket_accept -e http.sec_websocket_extensions -e http.sec_websocket_key -e http.sec_websocket_protocol -e http.sec_websocket_version -e http.server -e http.set_cookie -e http.transfer_encoding -e http.upgrade -e http
@flaviovdf
flaviovdf / gist:4071948
Created November 14, 2012 12:55
Vectorize example
# -*- coding: utf8
'''This module contains the code used for data conversion'''
from __future__ import division, print_function
from collections import defaultdict
from scipy import sparse
from sklearn.base import BaseEstimator
from sklearn.feature_extraction.text import Vectorizer