In [1]:
import numpy as np
import pandas as pd
import os
import sys
import operator
import numpy as np
import pandas as pd
from scipy import sparse
import xgboost as xgb
import random
from sklearn import model_selection, preprocessing, ensemble
from sklearn.metrics import log_loss
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer

import sklearn.cluster

import Levenshtein

from multiprocessing import Pool

from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.layers import Embedding
from keras.layers import Conv1D, Conv2D, GlobalMaxPooling1D, GlobalMaxPooling2D, MaxPooling1D
from keras.layers import Reshape
import keras

from keras.layers.merge import add, concatenate
from keras.models import Model
from keras.layers import Input

from keras.layers.merge import add, concatenate
from keras.models import Model
from keras.layers import Input

#from keras.layers.recurrent import GRU
from keras.layers import Flatten

import pickle


Using TensorFlow backend.

In [2]:
# process input data - NOT USED in stacker.py

train_df=pd.read_json('../input/train.json')
test_df=pd.read_json('../input/test.json')

train_info = train_df[['listing_id', 'interest_level']].copy()

tgts = ['low', 'medium', 'high']
target_num_map = {'low':0, 'medium':1, 'high':2}

train_info['interest_level'] = np.array(train_info['interest_level'].apply(lambda x: target_num_map[x]))
train_info.sort_values('listing_id', inplace=True)
train_info.set_index('listing_id', inplace=True)

info = (train_info, sorted(test_df.listing_id.values))
pickle.dump(info, open('stacker-info.pkl', 'wb'))

In [5]:
# process StackNet models (Level 1)

sncv_trainids = pd.read_csv('../stacknet-preleak/train_ids.csv', header=None)
sncv_preds = pd.read_csv('../stacknet-preleak/cv_preds1.csv', header=None)

ids = sncv_trainids[0].values.astype(np.int32)

#sn_tgts = ['sn_high', 'sn_medium', 'sn_low']
#sncv_preds.columns = sn_tgts
sncv_preds['listing_id'] = ids

sncv_preds.sort_values('listing_id', inplace=True)
sncv_preds.set_index('listing_id', inplace=True)

sn_testids = pd.read_csv('../stacknet-preleak/test_stacknet.csv', header=None)
sn_testpreds = pd.read_csv('../stacknet-preleak/cv_preds_test1.csv', header=None)

ids = sn_testids[0].values.astype(np.int32)

#sn_testpreds.columns = sn_tgts

sn_testpreds['listing_id'] = ids

sn_testpreds.sort_values('listing_id', inplace=True)
sn_testpreds.set_index('listing_id', inplace=True)

sn_preds1 = pd.concat([sn_testpreds, sncv_preds]).sort_index()
#sn_preds1.to_pickle('stacker-sn-l1.pkl')

In [7]:
import pickle

sn_testpredsa = [sn_testpreds.copy() for i in range(0, 5)]
pickle.dump((sn_preds1, sn_testpredsa), open('stacker-sn-l1.pkl', 'wb'))

In [ ]:
# process StackNet models (Level 2)

sncv_trainids = pd.read_csv('../stacknet/train_ids.csv', header=None)
sncv_preds = pd.read_csv('../stacknet/cv_preds2.csv', header=None)

ids = sncv_trainids[0].values.astype(np.int32)

sn_tgts = ['sn_high', 'sn_medium', 'sn_low']
sncv_preds.columns = sn_tgts
sncv_preds['listing_id'] = ids

sncv_preds.sort_values('listing_id', inplace=True)
sncv_preds.set_index('listing_id', inplace=True)

sn_testids = pd.read_csv('../stacknet/test_stacknet.csv', header=None)
sn_testpreds = pd.read_csv('../stacknet/sigma_stack_pred.csv', header=None)

ids = sn_testids[0].values.astype(np.int32)

sn_testpreds.columns = sn_tgts

sn_testpreds['listing_id'] = ids

sn_testpreds.sort_values('listing_id', inplace=True)
sn_testpreds.set_index('listing_id', inplace=True)

sn_preds2 = pd.concat([sn_testpreds, sncv_preds]).sort_index()
sn_preds2.to_pickle('stacker-sn-l2.pkl')

In [58]:
print(log_loss(train_info.interest_level, sn_preds2.loc[train_info.index, ['sn_low', 'sn_medium', 'sn_high']]))


0.535262721728

Code below here should wind up in stacker.py


In [34]:
class Stacker:
    def __init__(self, use, nn_shape = [(32, .1), (16, .1)]):
        self.train_info, self.test_ids = pd.read_pickle('stacker-info.pkl')
        
        self.nn_shape = nn_shape.copy()
        
        df_nn = use[0].copy()

        for i, df in enumerate(use[1:]):
            df_nn = pd.merge(df_nn, df, left_index = True, right_index = True)

        self.df_nn_train = df_nn.loc[self.train_info.index]
        self.df_nn_test = df_nn.loc[self.test_ids]
        
        self.test_x = np.array(self.df_nn_test.values)
        
        self.models = []
        self.df_folds = []
        self.test_preds = []

    # plenty of code to do this, but it's simple enough
    def oneheat(self, y):
        rv = np.zeros((len(y), 3))

        for i in [0, 1, 2]:
            rv[:,i] = (y == i)

        return rv
    
    def buildmodel(self, num_inputs, shape=[(32, .1), (16, .1)]):
        layers = [Input(shape=(num_inputs,))]

        for s in shape:
            layers.append(Dense(s[0], activation='relu')(layers[-1]))
            layers.append(Dropout(s[1])(layers[-1]))

        output = Dense(3, activation='softmax', name='output')(layers[-1])

        model = Model(inputs=layers[0], outputs=output)

        model.compile(loss='categorical_crossentropy',
                      optimizer='adam')

        return model


    def run_fold(self, train_idx, valid_idx):

        model = self.buildmodel(len(self.df_nn_train.keys()), shape=self.nn_shape)
        
        nn_fold_train = self.df_nn_train.iloc[train_idx]
        nn_fold_valid = self.df_nn_train.iloc[valid_idx]

        tmp_train_x = np.array(nn_fold_train.values)
        tmp_valid_x = np.array(nn_fold_valid.values)

        tmp_train_y = self.oneheat(self.train_info.iloc[train_idx].interest_level)
        tmp_valid_y = self.oneheat(self.train_info.iloc[valid_idx].interest_level)

        bst_model_path = 'tmpnnx.h5'

        ES = keras.callbacks.EarlyStopping(patience=12)
        MC = keras.callbacks.ModelCheckpoint(bst_model_path, save_best_only=True, save_weights_only=True)

        history = model.fit(tmp_train_x, tmp_train_y, batch_size=128, epochs=100, verbose=2, validation_data=(tmp_valid_x, tmp_valid_y), callbacks=[MC, ES])

        model.load_weights(bst_model_path)

        tpreds = model.predict(np.array(nn_fold_valid))

        df_tmp = pd.DataFrame(tpreds)

        df_tmp.columns = [['low', 'medium', 'high']]
        df_tmp['listing_id'] = nn_fold_valid.index
        df_tmp.set_index('listing_id', inplace=True)

        tgts = ['low', 'medium', 'high']
        print(log_loss(self.train_info.iloc[valid_idx].interest_level, df_tmp[tgts]))

        self.df_folds.append(df_tmp)
        
        self.test_preds.append(model.predict(self.test_x))
        
        self.models.append(model)
        
        return df_tmp
    
    def run(self, folds = 8, seed = 5000):        
        #print(folds)
        
        #self.kf_nn = model_selection.StratifiedKFold(n_splits=folds, shuffle=True, random_state=seed)
        #self.folds_nn = [(k[0], k[1]) for k in self.kf_nn.split(self.df_nn_train.index, self.train_info.interest_level)]
        
        self.kf = model_selection.KFold(n_splits=folds, shuffle=True, random_state=seed)
        self.folds_nn = [(k[0], k[1]) for k in self.kf.split(self.df_nn_train.index)]
        
        for fold in self.folds_nn:
            self.run_fold(fold[0], fold[1])
        
        self.df_cv = pd.concat(self.df_folds).sort_index()

        #log_loss(train_info.interest_level, df_cv[tgts])

        testarray = np.array(self.test_preds.copy())

        self.df_test = pd.DataFrame(testarray.mean(axis=0))
        self.df_test.columns = [['low', 'medium', 'high']]
        self.df_test['listing_id'] = self.test_ids
        self.df_test.set_index('listing_id', inplace=True)

        return self.df_cv, self.df_test

In [35]:
sn_preds1 = pd.read_pickle('stacker-sn-l1.pkl')
set_x1 = pd.read_pickle('0417-test.pkl')

In [ ]:


In [36]:
s = Stacker([set_x1, sn_preds1])

In [37]:
df_cv, df_test = s.run(folds=8)


Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.6368 - val_loss: 0.5338
Epoch 2/100
0s - loss: 0.5538 - val_loss: 0.5259
Epoch 3/100
0s - loss: 0.5420 - val_loss: 0.5199
Epoch 4/100
0s - loss: 0.5371 - val_loss: 0.5163
Epoch 5/100
0s - loss: 0.5341 - val_loss: 0.5147
Epoch 6/100
0s - loss: 0.5312 - val_loss: 0.5140
Epoch 7/100
0s - loss: 0.5305 - val_loss: 0.5144
Epoch 8/100
0s - loss: 0.5291 - val_loss: 0.5134
Epoch 9/100
0s - loss: 0.5280 - val_loss: 0.5152
Epoch 10/100
0s - loss: 0.5274 - val_loss: 0.5125
Epoch 11/100
0s - loss: 0.5283 - val_loss: 0.5124
Epoch 12/100
0s - loss: 0.5270 - val_loss: 0.5132
Epoch 13/100
0s - loss: 0.5257 - val_loss: 0.5135
Epoch 14/100
0s - loss: 0.5257 - val_loss: 0.5128
Epoch 15/100
0s - loss: 0.5260 - val_loss: 0.5127
Epoch 16/100
0s - loss: 0.5261 - val_loss: 0.5123
Epoch 17/100
0s - loss: 0.5254 - val_loss: 0.5119
Epoch 18/100
0s - loss: 0.5246 - val_loss: 0.5124
Epoch 19/100
0s - loss: 0.5254 - val_loss: 0.5114
Epoch 20/100
0s - loss: 0.5243 - val_loss: 0.5113
Epoch 21/100
0s - loss: 0.5245 - val_loss: 0.5128
Epoch 22/100
0s - loss: 0.5247 - val_loss: 0.5114
Epoch 23/100
0s - loss: 0.5249 - val_loss: 0.5118
Epoch 24/100
0s - loss: 0.5238 - val_loss: 0.5115
Epoch 25/100
0s - loss: 0.5240 - val_loss: 0.5121
Epoch 26/100
0s - loss: 0.5238 - val_loss: 0.5130
Epoch 27/100
0s - loss: 0.5243 - val_loss: 0.5117
Epoch 28/100
0s - loss: 0.5236 - val_loss: 0.5124
Epoch 29/100
0s - loss: 0.5239 - val_loss: 0.5127
Epoch 30/100
0s - loss: 0.5229 - val_loss: 0.5127
Epoch 31/100
0s - loss: 0.5237 - val_loss: 0.5149
Epoch 32/100
0s - loss: 0.5242 - val_loss: 0.5118
Epoch 33/100
0s - loss: 0.5234 - val_loss: 0.5119
0.511253658536
Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.6053 - val_loss: 0.5538
Epoch 2/100
0s - loss: 0.5386 - val_loss: 0.5432
Epoch 3/100
0s - loss: 0.5315 - val_loss: 0.5391
Epoch 4/100
0s - loss: 0.5298 - val_loss: 0.5349
Epoch 5/100
0s - loss: 0.5258 - val_loss: 0.5358
Epoch 6/100
0s - loss: 0.5262 - val_loss: 0.5363
Epoch 7/100
0s - loss: 0.5245 - val_loss: 0.5327
Epoch 8/100
0s - loss: 0.5242 - val_loss: 0.5343
Epoch 9/100
0s - loss: 0.5232 - val_loss: 0.5361
Epoch 10/100
0s - loss: 0.5227 - val_loss: 0.5333
Epoch 11/100
0s - loss: 0.5230 - val_loss: 0.5330
Epoch 12/100
0s - loss: 0.5225 - val_loss: 0.5327
Epoch 13/100
0s - loss: 0.5226 - val_loss: 0.5337
Epoch 14/100
0s - loss: 0.5229 - val_loss: 0.5378
Epoch 15/100
0s - loss: 0.5226 - val_loss: 0.5332
Epoch 16/100
0s - loss: 0.5221 - val_loss: 0.5345
Epoch 17/100
0s - loss: 0.5224 - val_loss: 0.5330
Epoch 18/100
0s - loss: 0.5216 - val_loss: 0.5324
Epoch 19/100
0s - loss: 0.5209 - val_loss: 0.5321
Epoch 20/100
0s - loss: 0.5211 - val_loss: 0.5322
Epoch 21/100
0s - loss: 0.5213 - val_loss: 0.5330
Epoch 22/100
0s - loss: 0.5207 - val_loss: 0.5341
Epoch 23/100
0s - loss: 0.5213 - val_loss: 0.5325
Epoch 24/100
0s - loss: 0.5214 - val_loss: 0.5332
Epoch 25/100
0s - loss: 0.5216 - val_loss: 0.5324
Epoch 26/100
0s - loss: 0.5219 - val_loss: 0.5327
Epoch 27/100
0s - loss: 0.5207 - val_loss: 0.5314
Epoch 28/100
0s - loss: 0.5200 - val_loss: 0.5322
Epoch 29/100
0s - loss: 0.5214 - val_loss: 0.5320
Epoch 30/100
0s - loss: 0.5206 - val_loss: 0.5313
Epoch 31/100
0s - loss: 0.5208 - val_loss: 0.5320
Epoch 32/100
0s - loss: 0.5201 - val_loss: 0.5316
Epoch 33/100
0s - loss: 0.5209 - val_loss: 0.5324
Epoch 34/100
0s - loss: 0.5207 - val_loss: 0.5312
Epoch 35/100
0s - loss: 0.5200 - val_loss: 0.5318
Epoch 36/100
0s - loss: 0.5204 - val_loss: 0.5306
Epoch 37/100
0s - loss: 0.5200 - val_loss: 0.5338
Epoch 38/100
0s - loss: 0.5201 - val_loss: 0.5348
Epoch 39/100
0s - loss: 0.5195 - val_loss: 0.5314
Epoch 40/100
0s - loss: 0.5205 - val_loss: 0.5322
Epoch 41/100
0s - loss: 0.5202 - val_loss: 0.5320
Epoch 42/100
0s - loss: 0.5209 - val_loss: 0.5316
Epoch 43/100
0s - loss: 0.5199 - val_loss: 0.5320
Epoch 44/100
0s - loss: 0.5208 - val_loss: 0.5318
Epoch 45/100
0s - loss: 0.5207 - val_loss: 0.5313
Epoch 46/100
0s - loss: 0.5196 - val_loss: 0.5309
Epoch 47/100
0s - loss: 0.5201 - val_loss: 0.5347
Epoch 48/100
0s - loss: 0.5193 - val_loss: 0.5317
Epoch 49/100
0s - loss: 0.5196 - val_loss: 0.5313
0.530621064815
Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.5777 - val_loss: 0.5452
Epoch 2/100
0s - loss: 0.5419 - val_loss: 0.5351
Epoch 3/100
0s - loss: 0.5350 - val_loss: 0.5316
Epoch 4/100
0s - loss: 0.5308 - val_loss: 0.5288
Epoch 5/100
0s - loss: 0.5302 - val_loss: 0.5283
Epoch 6/100
0s - loss: 0.5273 - val_loss: 0.5289
Epoch 7/100
0s - loss: 0.5274 - val_loss: 0.5291
Epoch 8/100
0s - loss: 0.5256 - val_loss: 0.5266
Epoch 9/100
0s - loss: 0.5252 - val_loss: 0.5275
Epoch 10/100
0s - loss: 0.5247 - val_loss: 0.5318
Epoch 11/100
0s - loss: 0.5251 - val_loss: 0.5278
Epoch 12/100
0s - loss: 0.5241 - val_loss: 0.5296
Epoch 13/100
0s - loss: 0.5234 - val_loss: 0.5268
Epoch 14/100
0s - loss: 0.5235 - val_loss: 0.5286
Epoch 15/100
0s - loss: 0.5230 - val_loss: 0.5278
Epoch 16/100
0s - loss: 0.5241 - val_loss: 0.5272
Epoch 17/100
0s - loss: 0.5234 - val_loss: 0.5269
Epoch 18/100
0s - loss: 0.5219 - val_loss: 0.5286
Epoch 19/100
0s - loss: 0.5221 - val_loss: 0.5262
Epoch 20/100
0s - loss: 0.5225 - val_loss: 0.5265
Epoch 21/100
0s - loss: 0.5217 - val_loss: 0.5275
Epoch 22/100
0s - loss: 0.5225 - val_loss: 0.5271
Epoch 23/100
0s - loss: 0.5222 - val_loss: 0.5271
Epoch 24/100
0s - loss: 0.5225 - val_loss: 0.5252
Epoch 25/100
0s - loss: 0.5216 - val_loss: 0.5265
Epoch 26/100
0s - loss: 0.5219 - val_loss: 0.5260
Epoch 27/100
0s - loss: 0.5215 - val_loss: 0.5261
Epoch 28/100
0s - loss: 0.5212 - val_loss: 0.5255
Epoch 29/100
0s - loss: 0.5220 - val_loss: 0.5274
Epoch 30/100
0s - loss: 0.5212 - val_loss: 0.5255
Epoch 31/100
0s - loss: 0.5209 - val_loss: 0.5267
Epoch 32/100
0s - loss: 0.5220 - val_loss: 0.5258
Epoch 33/100
0s - loss: 0.5210 - val_loss: 0.5286
Epoch 34/100
0s - loss: 0.5209 - val_loss: 0.5263
Epoch 35/100
0s - loss: 0.5208 - val_loss: 0.5262
Epoch 36/100
0s - loss: 0.5221 - val_loss: 0.5260
Epoch 37/100
0s - loss: 0.5211 - val_loss: 0.5259
0.52519753872
Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.6105 - val_loss: 0.5432
Epoch 2/100
0s - loss: 0.5446 - val_loss: 0.5390
Epoch 3/100
0s - loss: 0.5354 - val_loss: 0.5298
Epoch 4/100
0s - loss: 0.5324 - val_loss: 0.5271
Epoch 5/100
0s - loss: 0.5304 - val_loss: 0.5264
Epoch 6/100
0s - loss: 0.5274 - val_loss: 0.5262
Epoch 7/100
0s - loss: 0.5275 - val_loss: 0.5263
Epoch 8/100
0s - loss: 0.5272 - val_loss: 0.5253
Epoch 9/100
0s - loss: 0.5263 - val_loss: 0.5266
Epoch 10/100
0s - loss: 0.5258 - val_loss: 0.5248
Epoch 11/100
0s - loss: 0.5273 - val_loss: 0.5245
Epoch 12/100
0s - loss: 0.5255 - val_loss: 0.5234
Epoch 13/100
0s - loss: 0.5252 - val_loss: 0.5243
Epoch 14/100
0s - loss: 0.5258 - val_loss: 0.5243
Epoch 15/100
0s - loss: 0.5249 - val_loss: 0.5235
Epoch 16/100
0s - loss: 0.5249 - val_loss: 0.5236
Epoch 17/100
0s - loss: 0.5242 - val_loss: 0.5243
Epoch 18/100
0s - loss: 0.5238 - val_loss: 0.5241
Epoch 19/100
0s - loss: 0.5237 - val_loss: 0.5240
Epoch 20/100
0s - loss: 0.5238 - val_loss: 0.5261
Epoch 21/100
0s - loss: 0.5240 - val_loss: 0.5235
Epoch 22/100
0s - loss: 0.5237 - val_loss: 0.5257
Epoch 23/100
0s - loss: 0.5234 - val_loss: 0.5244
Epoch 24/100
0s - loss: 0.5236 - val_loss: 0.5231
Epoch 25/100
0s - loss: 0.5232 - val_loss: 0.5241
Epoch 26/100
0s - loss: 0.5236 - val_loss: 0.5239
Epoch 27/100
0s - loss: 0.5230 - val_loss: 0.5245
Epoch 28/100
0s - loss: 0.5220 - val_loss: 0.5251
Epoch 29/100
0s - loss: 0.5234 - val_loss: 0.5231
Epoch 30/100
0s - loss: 0.5223 - val_loss: 0.5237
Epoch 31/100
0s - loss: 0.5233 - val_loss: 0.5232
Epoch 32/100
0s - loss: 0.5223 - val_loss: 0.5237
Epoch 33/100
0s - loss: 0.5215 - val_loss: 0.5253
Epoch 34/100
0s - loss: 0.5228 - val_loss: 0.5227
Epoch 35/100
0s - loss: 0.5230 - val_loss: 0.5234
Epoch 36/100
0s - loss: 0.5221 - val_loss: 0.5238
Epoch 37/100
0s - loss: 0.5225 - val_loss: 0.5230
Epoch 38/100
0s - loss: 0.5220 - val_loss: 0.5235
Epoch 39/100
0s - loss: 0.5227 - val_loss: 0.5221
Epoch 40/100
0s - loss: 0.5220 - val_loss: 0.5225
Epoch 41/100
0s - loss: 0.5223 - val_loss: 0.5235
Epoch 42/100
0s - loss: 0.5227 - val_loss: 0.5224
Epoch 43/100
0s - loss: 0.5222 - val_loss: 0.5229
Epoch 44/100
0s - loss: 0.5236 - val_loss: 0.5255
Epoch 45/100
0s - loss: 0.5218 - val_loss: 0.5230
Epoch 46/100
0s - loss: 0.5217 - val_loss: 0.5234
Epoch 47/100
0s - loss: 0.5219 - val_loss: 0.5226
Epoch 48/100
0s - loss: 0.5227 - val_loss: 0.5238
Epoch 49/100
0s - loss: 0.5221 - val_loss: 0.5229
Epoch 50/100
0s - loss: 0.5218 - val_loss: 0.5248
Epoch 51/100
0s - loss: 0.5206 - val_loss: 0.5227
Epoch 52/100
0s - loss: 0.5220 - val_loss: 0.5235
0.522095753839
Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.6031 - val_loss: 0.5387
Epoch 2/100
0s - loss: 0.5438 - val_loss: 0.5327
Epoch 3/100
0s - loss: 0.5367 - val_loss: 0.5272
Epoch 4/100
0s - loss: 0.5314 - val_loss: 0.5262
Epoch 5/100
0s - loss: 0.5299 - val_loss: 0.5255
Epoch 6/100
0s - loss: 0.5283 - val_loss: 0.5270
Epoch 7/100
0s - loss: 0.5266 - val_loss: 0.5248
Epoch 8/100
0s - loss: 0.5263 - val_loss: 0.5251
Epoch 9/100
0s - loss: 0.5254 - val_loss: 0.5257
Epoch 10/100
0s - loss: 0.5253 - val_loss: 0.5262
Epoch 11/100
0s - loss: 0.5236 - val_loss: 0.5251
Epoch 12/100
0s - loss: 0.5243 - val_loss: 0.5253
Epoch 13/100
0s - loss: 0.5231 - val_loss: 0.5252
Epoch 14/100
0s - loss: 0.5234 - val_loss: 0.5254
Epoch 15/100
0s - loss: 0.5234 - val_loss: 0.5250
Epoch 16/100
0s - loss: 0.5241 - val_loss: 0.5249
Epoch 17/100
0s - loss: 0.5225 - val_loss: 0.5282
Epoch 18/100
0s - loss: 0.5229 - val_loss: 0.5260
Epoch 19/100
0s - loss: 0.5235 - val_loss: 0.5256
Epoch 20/100
0s - loss: 0.5234 - val_loss: 0.5257
0.52477001677
Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.6165 - val_loss: 0.5278
Epoch 2/100
0s - loss: 0.5508 - val_loss: 0.5253
Epoch 3/100
0s - loss: 0.5441 - val_loss: 0.5192
Epoch 4/100
0s - loss: 0.5397 - val_loss: 0.5156
Epoch 5/100
0s - loss: 0.5349 - val_loss: 0.5140
Epoch 6/100
0s - loss: 0.5331 - val_loss: 0.5146
Epoch 7/100
0s - loss: 0.5315 - val_loss: 0.5120
Epoch 8/100
0s - loss: 0.5312 - val_loss: 0.5119
Epoch 9/100
0s - loss: 0.5291 - val_loss: 0.5112
Epoch 10/100
0s - loss: 0.5297 - val_loss: 0.5103
Epoch 11/100
0s - loss: 0.5295 - val_loss: 0.5118
Epoch 12/100
0s - loss: 0.5290 - val_loss: 0.5106
Epoch 13/100
0s - loss: 0.5286 - val_loss: 0.5110
Epoch 14/100
0s - loss: 0.5284 - val_loss: 0.5105
Epoch 15/100
0s - loss: 0.5272 - val_loss: 0.5104
Epoch 16/100
0s - loss: 0.5282 - val_loss: 0.5122
Epoch 17/100
0s - loss: 0.5281 - val_loss: 0.5120
Epoch 18/100
0s - loss: 0.5271 - val_loss: 0.5093
Epoch 19/100
0s - loss: 0.5253 - val_loss: 0.5115
Epoch 20/100
0s - loss: 0.5265 - val_loss: 0.5107
Epoch 21/100
0s - loss: 0.5256 - val_loss: 0.5104
Epoch 22/100
0s - loss: 0.5266 - val_loss: 0.5094
Epoch 23/100
0s - loss: 0.5257 - val_loss: 0.5121
Epoch 24/100
0s - loss: 0.5262 - val_loss: 0.5099
Epoch 25/100
0s - loss: 0.5254 - val_loss: 0.5091
Epoch 26/100
0s - loss: 0.5262 - val_loss: 0.5126
Epoch 27/100
0s - loss: 0.5258 - val_loss: 0.5088
Epoch 28/100
0s - loss: 0.5260 - val_loss: 0.5110
Epoch 29/100
0s - loss: 0.5246 - val_loss: 0.5136
Epoch 30/100
0s - loss: 0.5258 - val_loss: 0.5088
Epoch 31/100
0s - loss: 0.5245 - val_loss: 0.5091
Epoch 32/100
0s - loss: 0.5247 - val_loss: 0.5118
Epoch 33/100
0s - loss: 0.5247 - val_loss: 0.5112
Epoch 34/100
0s - loss: 0.5246 - val_loss: 0.5106
Epoch 35/100
0s - loss: 0.5245 - val_loss: 0.5097
Epoch 36/100
0s - loss: 0.5241 - val_loss: 0.5097
Epoch 37/100
0s - loss: 0.5241 - val_loss: 0.5109
Epoch 38/100
0s - loss: 0.5244 - val_loss: 0.5106
Epoch 39/100
0s - loss: 0.5247 - val_loss: 0.5103
Epoch 40/100
0s - loss: 0.5238 - val_loss: 0.5097
Epoch 41/100
0s - loss: 0.5242 - val_loss: 0.5111
Epoch 42/100
0s - loss: 0.5239 - val_loss: 0.5111
Epoch 43/100
0s - loss: 0.5238 - val_loss: 0.5106
0.508775690948
Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.5707 - val_loss: 0.5298
Epoch 2/100
0s - loss: 0.5413 - val_loss: 0.5243
Epoch 3/100
0s - loss: 0.5332 - val_loss: 0.5215
Epoch 4/100
0s - loss: 0.5307 - val_loss: 0.5185
Epoch 5/100
0s - loss: 0.5300 - val_loss: 0.5180
Epoch 6/100
0s - loss: 0.5282 - val_loss: 0.5183
Epoch 7/100
0s - loss: 0.5275 - val_loss: 0.5184
Epoch 8/100
0s - loss: 0.5269 - val_loss: 0.5176
Epoch 9/100
0s - loss: 0.5273 - val_loss: 0.5183
Epoch 10/100
0s - loss: 0.5265 - val_loss: 0.5181
Epoch 11/100
0s - loss: 0.5253 - val_loss: 0.5175
Epoch 12/100
0s - loss: 0.5255 - val_loss: 0.5208
Epoch 13/100
0s - loss: 0.5244 - val_loss: 0.5180
Epoch 14/100
0s - loss: 0.5257 - val_loss: 0.5173
Epoch 15/100
0s - loss: 0.5247 - val_loss: 0.5193
Epoch 16/100
0s - loss: 0.5245 - val_loss: 0.5179
Epoch 17/100
0s - loss: 0.5245 - val_loss: 0.5163
Epoch 18/100
0s - loss: 0.5235 - val_loss: 0.5170
Epoch 19/100
0s - loss: 0.5237 - val_loss: 0.5172
Epoch 20/100
0s - loss: 0.5235 - val_loss: 0.5172
Epoch 21/100
0s - loss: 0.5230 - val_loss: 0.5163
Epoch 22/100
0s - loss: 0.5236 - val_loss: 0.5174
Epoch 23/100
0s - loss: 0.5234 - val_loss: 0.5165
Epoch 24/100
0s - loss: 0.5233 - val_loss: 0.5176
Epoch 25/100
0s - loss: 0.5225 - val_loss: 0.5167
Epoch 26/100
0s - loss: 0.5233 - val_loss: 0.5166
Epoch 27/100
0s - loss: 0.5226 - val_loss: 0.5165
Epoch 28/100
0s - loss: 0.5232 - val_loss: 0.5177
Epoch 29/100
0s - loss: 0.5231 - val_loss: 0.5175
Epoch 30/100
0s - loss: 0.5232 - val_loss: 0.5163
Epoch 31/100
0s - loss: 0.5231 - val_loss: 0.5166
Epoch 32/100
0s - loss: 0.5220 - val_loss: 0.5170
Epoch 33/100
0s - loss: 0.5230 - val_loss: 0.5157
Epoch 34/100
0s - loss: 0.5220 - val_loss: 0.5163
Epoch 35/100
0s - loss: 0.5220 - val_loss: 0.5161
Epoch 36/100
0s - loss: 0.5228 - val_loss: 0.5164
Epoch 37/100
0s - loss: 0.5224 - val_loss: 0.5174
Epoch 38/100
0s - loss: 0.5216 - val_loss: 0.5159
Epoch 39/100
0s - loss: 0.5219 - val_loss: 0.5172
Epoch 40/100
0s - loss: 0.5221 - val_loss: 0.5161
Epoch 41/100
0s - loss: 0.5217 - val_loss: 0.5174
Epoch 42/100
0s - loss: 0.5215 - val_loss: 0.5168
Epoch 43/100
0s - loss: 0.5225 - val_loss: 0.5166
Epoch 44/100
0s - loss: 0.5220 - val_loss: 0.5169
Epoch 45/100
0s - loss: 0.5218 - val_loss: 0.5170
Epoch 46/100
0s - loss: 0.5218 - val_loss: 0.5164
0.51570717216
Train on 43183 samples, validate on 6169 samples
Epoch 1/100
1s - loss: 0.6417 - val_loss: 0.5250
Epoch 2/100
0s - loss: 0.5503 - val_loss: 0.5171
Epoch 3/100
0s - loss: 0.5433 - val_loss: 0.5099
Epoch 4/100
0s - loss: 0.5377 - val_loss: 0.5095
Epoch 5/100
0s - loss: 0.5339 - val_loss: 0.5126
Epoch 6/100
0s - loss: 0.5319 - val_loss: 0.5066
Epoch 7/100
0s - loss: 0.5311 - val_loss: 0.5048
Epoch 8/100
0s - loss: 0.5308 - val_loss: 0.5035
Epoch 9/100
0s - loss: 0.5299 - val_loss: 0.5033
Epoch 10/100
0s - loss: 0.5286 - val_loss: 0.5031
Epoch 11/100
0s - loss: 0.5283 - val_loss: 0.5022
Epoch 12/100
0s - loss: 0.5268 - val_loss: 0.5030
Epoch 13/100
0s - loss: 0.5283 - val_loss: 0.5030
Epoch 14/100
0s - loss: 0.5272 - val_loss: 0.5025
Epoch 15/100
0s - loss: 0.5272 - val_loss: 0.5034
Epoch 16/100
0s - loss: 0.5267 - val_loss: 0.5025
Epoch 17/100
0s - loss: 0.5268 - val_loss: 0.5014
Epoch 18/100
0s - loss: 0.5267 - val_loss: 0.5039
Epoch 19/100
0s - loss: 0.5267 - val_loss: 0.5030
Epoch 20/100
0s - loss: 0.5256 - val_loss: 0.5023
Epoch 21/100
0s - loss: 0.5263 - val_loss: 0.5027
Epoch 22/100
0s - loss: 0.5254 - val_loss: 0.5045
Epoch 23/100
0s - loss: 0.5253 - val_loss: 0.5024
Epoch 24/100
0s - loss: 0.5259 - val_loss: 0.5022
Epoch 25/100
0s - loss: 0.5258 - val_loss: 0.5023
Epoch 26/100
0s - loss: 0.5258 - val_loss: 0.5019
Epoch 27/100
0s - loss: 0.5251 - val_loss: 0.5015
Epoch 28/100
0s - loss: 0.5255 - val_loss: 0.5030
Epoch 29/100
0s - loss: 0.5250 - val_loss: 0.5022
Epoch 30/100
0s - loss: 0.5254 - val_loss: 0.5030
0.501369543448

In [38]:
log_loss(s.train_info.interest_level, df_cv[['low', 'medium', 'high']])


Out[38]:
0.51747380490436345

In [39]:
df_test.to_csv('stacker-test2.csv.gz', compression='gzip')

In [46]:
import time

In [49]:
int(np.floor(time.time() * 1000))


Out[49]:
1492489815424

In [ ]:
'abcd'