Skip to content

Instantly share code, notes, and snippets.

@IevaZarina
IevaZarina / GiftExchangePairGenerator.py
Last active August 29, 2015 14:10
Xmas Gift Exchange
# -*- 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:
@IevaZarina
IevaZarina / text_cleaning.py
Last active August 16, 2023 18:29
Cleaning lines of text
# -*- 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:
@IevaZarina
IevaZarina / xgboost_iris_prediction.py
Last active February 24, 2024 18:08
Simple demo script for running Xgboost
# 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
"'{\"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\"}]}'"
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
@IevaZarina
IevaZarina / depth-first-search.py
Created November 7, 2016 21:17
Simple depth-first searcher in Python 2.7
'''
Depth-first searcher
Tree:
a
/ \
b c
/|\ \
d e f g
|
@IevaZarina
IevaZarina / aho-corasick-automata.py
Created November 24, 2016 23:27
Simple test case for aho-corasick automata for keyword search.
import ahocorasick as ahc
keywords = [
('he', 1),
('she', 1),
('hers', 1),
('her', 1)
]
text = [
@IevaZarina
IevaZarina / simple-supervised-knn.py
Created June 16, 2017 13:58
Simple supervised KNN classification in Python 2.7
# knn
import math
from collections import defaultdict
from operator import itemgetter
# Some handmade train/test data
X_train = [
[1, 1],