This file contains 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
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 |
This file contains 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
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 = [] |
This file contains 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 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 |
This file contains 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 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(): |
This file contains 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 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 |
This file contains 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
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) |
This file contains 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
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] | |
This file contains 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
#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; |
This file contains 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
#!/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) |
This file contains 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
#!/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 |
NewerOlder