Instantly share code, notes, and snippets.

View simple-supervised-knn.py
# knn
import math
from collections import defaultdict
from operator import itemgetter
# Some handmade train/test data
X_train = [
[1, 1],
View aho-corasick-automata.py
import ahocorasick as ahc
keywords = [
('he', 1),
('she', 1),
('hers', 1),
('her', 1)
]
text = [
View depth-first-search.py
'''
Depth-first searcher
Tree:
a
/ \
b c
/|\ \
d e f g
|
View plot_without_ui.py
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.decomposition import TruncatedSVD
# Enable saving plot to png file without UI
plt.switch_backend('agg')
iris = datasets.load_iris()
X = iris.data
y = iris.target
View animals.json
"'{\"animal_list\": [{\"type\": \"mammal\", \"description\": \"Tall, with brown spots, lives in Savanna\", \"name\": \"Giraffa camelopardalis\"},{\"type\": \"mammal\", \"description\": \"Big, grey, with big ears, smart\", \"name\": \"Loxodonta africana\"},{\"type\": \"reptile\", \"description\": \"Green, changes color, lives in \"East Africa\"\", \"name\": \"Trioceros jacksonii\"}]}'"
View xgboost_iris_prediction.py
# Ieva Zarina, 2016, licensed under the Apache 2.0 licnese
import numpy as np
import xgboost as xgb
from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn.datasets import dump_svmlight_file
from sklearn.externals import joblib
from sklearn.metrics import precision_score
View text_cleaning.py
# -*- coding: utf-8 -*-
# Ieva Zarina, 2016, licensed under the Apache 2.0 licnece
import re
def is_digit(word):
try:
int(word)
return True
except ValueError:
View GiftExchangePairGenerator.py
# -*- coding: utf-8 -*-
import random
def getRandomPerson(ppl):
return ppl[random.randint(0,len(ppl)-1)]
def good_pair(ignore_ppl, chosen1, chosen2):
for pair in ignore_ppl: