Skip to content

Instantly share code, notes, and snippets.

def qwk(a1, a2):
"""
Source: https://www.kaggle.com/c/data-science-bowl-2019/discussion/114133#latest-660168
:param a1:
:param a2:
:param max_rat:
:return:
"""
max_rat = 3
def re_ranking(model, probFea,galFea,k1,k2,lambda_value):
query_num = probFea.shape[0]
all_num = query_num + galFea.shape[0]
feat = np.append(probFea,galFea,axis = 0)
feat = feat.astype(np.float16)
feat = torch.from_numpy(feat).half().cuda()
print('computing original distance')
sz = feat.shape[0]
d = []
import os
from sqlalchemy import create_engine
from sqlalchemy.types import VARCHAR
from pandas.io.sql import SQLTable, pandasSQL_builder
import tempfile
import numpy as np
import boto3
import json
import pandas as pd
from sqlalchemy import text
import logging
import logging.handlers
import os
def get_logger(log_name, logdir=None, loglevel=logging.INFO):
_logger = logging.getLogger(log_name)
fmt = '%(asctime)s [%(levelname)s] %(message)s'
formatter = logging.Formatter(fmt)
if not _logger.hasHandlers():
# from https://www.kaggle.com/samratp/wordbatch-ridge-fm-frtl-target-encoding-lgbm/notebook
class TargetEncoder:
# Adapted from https://www.kaggle.com/ogrellier/python-target-encoding-for-categorical-features
def __repr__(self):
return 'TargetEncoder'
def __init__(self, smoothing=1, min_samples_leaf=1, noise_level=0, keep_original=False, suffix='enc'):
self.smoothing = smoothing
self.min_samples_leaf = min_samples_leaf
@e-mon
e-mon / init.lua
Created May 15, 2017 15:01
vim-like keybind for hammerspoon
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
hs.timer.usleep(1000)
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
end
end
local function keyCodeSet(keys)
class UnionFind:
def __init__(self, N):
self.rank = [0]*N
self.par = list(range(N))
def find(self, x):
if x != self.par[x]:
self.par[x] = self.find(self.par[x])
return self.par[x]
@e-mon
e-mon / game.cpp
Last active January 12, 2016 05:56
samurAI manager
#include "samurai.hpp"
#include <thread>
#include <signal.h>
Role::Role(int id, CommentedIStream& cs): id(id) {
int reachSize;
cs >> reachSize;
for (int k = 0; k != reachSize; k++) {
int x, y;
cs >> x >> y;
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from heapq import heappush, heappop
q = []
for i in range(10**7):
heappush(q,[i, 10*i])
while q != []:
x,y = heappop(q)
@e-mon
e-mon / simple.py
Created June 28, 2015 19:26
SIMPLE
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from math import log
from collections import Counter,defaultdict
from functools import reduce
from itertools import chain
import Help