Instantly share code, notes, and snippets.

@cynthia /lezhin_model.py Secret
Created Aug 12, 2017

Embed
What would you like to do?
#!/usr/bin/env python3
# Lezhin Data Challenge Prediction "Model"
# Copyright (c) 2017 Sangwhan Moon. Commercial use strictly prohibited.
#
# Requirements: Python 3.5+
from base64 import b64decode as bd
from bz2 import decompress as dc
# FIXME: Maybe the 0 string values should be made into empty strings.
ttf = lambda l, dt=1: [int(e) for e in l[dt:dt + 6]] + [l[dt + 6], l[dt + 7]] + [int(e) for e in l[dt + 8:dt + 15]] + [l[dt + 15], int(l[dt + 16]), l[dt + 17]] + [int(e) for e in l[dt + 18:dt + 160]] + [float(e) for e in l[dt + 160:]]
rtsv = lambda s: [e.strip() for e in s.split("\t")]
dcs = lambda s: dc(s).decode()
def predict(x, dt=1):
if type(x) == str:
x = ttf(rtsv(x), dt=dt)
if sum([1 for i in range(len(x)) if type(x[i]) != type(sp[i])]) > 0:
raise "Type mismatch in feature dimensions for input x"
return 1 if x[8] != 0 and sum([x[9], x[10], x[11], x[12], x[13], x[14]]) > 0 else 0
sp = ttf(rtsv(dcs(bd(b'QlpoOTFBWSZTWdUi0LMAALfcAAAwAAF/4DsAIACRFNBhNPKASakJPE1GhaQgXSTCQyz07TAxYCyKF0LJth2mGT4lGeWtms2qAO5JIdJJK5JSCEWAd1RxJdCzSPlbN561Trp85nZjTpzDclrlQncFcgeid/F3JFOFCQ1SLQsw'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment