Kaggle competition: Jigsaw Multilingual Toxic Comment Classification
<SOS> metric: AUC Kaggle data source: jigsaw-multilingual-toxic-comment-classification<prepare_x_and_y>
import os
import numpy
from sklearn import metrics
import pandas as pd
from sklearn.metrics import roc_auc_score
def transform(train_df, player_features, game_features,test=False):
X_train = np.array(train_df[player_features] ).reshape(-1, len(player_features)*22)
 X_play_col = np.zeros(shape=(X_train.shape[0], len(game_features)))
 for i, col in enumerate(game_features):
X_play_col[:, i] = train_df[col][::22]
X_train = X_play_col
y_train = np.zeros(shape=(X_train.shape[0], 199))
if not test:
for i,yard in enumerate(train_df[TARGET][::22]):
y_train[i, yard+99:] = np.ones(shape=(1, 100-yard))
if not test:
scaler.fit(X_train)
 X_train = scaler.transform(X_train)
 return X_train, y_train<compute_test_metric>
wr = open('results.txt', "w", encoding='utf8')
 mybest = pd.read_csv('/kaggle/input/mybest/sub9523.csv')
 sub = pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-test-translated/jigsaw_miltilingual_test_translated.csv')
 sub1 = pd.read_csv('/kaggle/input/mysub42/sub9458.csv')
 sub['prd'] = sub1['toxic']
for p0 in numpy.arange(1.2, 1.3, 0.1):
for p1 in numpy.arange(0.6, 0.7, 0.1):
for p2 in numpy.arange(0.8, 0.9, 0.1):
for p3 in numpy.arange(0.6, 0.7, 0.1):
for p4 in numpy.arange(0.6, 0.7, 0.1):
for p5 in numpy.arange(0.6, 0.7, 0.1):
out = []
for _, row in sub.iterrows() :
item = [row['id'], row['prd'], row['lang']]
if(item[2]=='es'):
if(item[1]<0.7):
item[1] *= p0
elif(item[2]=='fr'):
if(item[1]<0.7):
item[1] *= p1
elif(item[2]=='ru'):
if(item[1]<0.7):
item[1] *= p2
elif(item[2]=='it'):
if(item[1]<0.7):
item[1] *= p3
elif(item[2]=='tr'):
if(item[1]<0.7):
item[1] *= p4
elif(item[2]=='pt'):
if(item[1]<0.7):
item[1] *= p5
out.append(item)
 of = pd.DataFrame(out, columns=['id', 'toxic', 'lang'])
 score1 = roc_auc_score(mybest.toxic.round().astype(int), of.toxic.values)
 score2 = roc_auc_score(of.toxic.round().astype(int), mybest.toxic.values)
 line = '%1.2f,%1.2f,%1.2f,%1.2f,%1.2f,%1.2f\t%2.4f\t%2.4f'%(p0, p1,p2,p3,p4,p5, 100*score1, 100*score2)
 print(line)
 wr.write(line+'
')
 wr.close()
def crps(y_true, y_pred):
return K.mean(K.square(y_true - K.cumsum(y_pred, axis=1)) , axis=1 )<choose_model_class>
wr = open('results.txt', "w", encoding='utf8')
 mybest = pd.read_csv('/kaggle/input/mybest/sub9523.csv')
 sub = pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-test-translated/jigsaw_miltilingual_test_translated.csv')
 sub1 = pd.read_csv('/kaggle/input/mysub42/sub9458.csv')
 sub['prd'] = sub1['toxic']
dic = {}
oft = open('/kaggle/input/profanity/Profanity.txt', "r", encoding='utf8')
 for l in oft:
ele = l.strip().lower().split(':')
 dic[ele[0]] = ele[1]
oft.close()
len, les, lit, ltr, lfr, lru, lpt = 1., 1., 1., 1., 1., 1., 1.
 enpros = dic['en'].split(',')
 for len in numpy.arange(1.3, 1.4, 0.1):
out = []
found = 0
for _, row in sub.iterrows() :
if(row['lang']=='es'):
lmd = les
elif(row['lang']=='it'):
lmd = lit
elif(row['lang']=='tr'):
lmd = ltr
elif(row['lang']=='fr'):
lmd = lfr
elif(row['lang']=='ru'):
lmd = lru
else:
lmd = lpt
item = [row['id'], row['prd']]
if(item[1]<0.5):
for w in enpros:
if(str(row['translated'] ).lower().find(w)>=0):
item[1] *= len
found += 1
break
ws = dic[row['lang']].split(',')
 for w in ws:
if(str(row['content'] ).lower().find(w)>=0):
item[1] *= lmd
break
out.append(item)
 of = pd.DataFrame(out, columns=['id', 'toxic'])
 score1 = roc_auc_score(mybest.toxic.round().astype(int), of.toxic.values)
 score2 = roc_auc_score(of.toxic.round().astype(int), mybest.toxic.values)
 l = '%1.2f:\t%2.4f\t%2.4f'%(len, 100*score1, 100*score2)
 print(found, l)
 wr.write(l+'
')
 wr.close()