train_['rel'], qids_val.values, metric=metric) model = LambdaMART(metric=metric, max_depth=10, n_estimators=1000, learning_rate=.1, verbose=1, max_features=0.5, query_subsample=0.5, max_leaf_nodes=10, min_samples_leaf=64) model.fit(train_[m2_rnn], train_['rel'], qids_val, monitor=monitor) #creating the data to test the models with LambdaMART_testX = test_[m2_rnn].set_index('srch_id').sort_index() LambdaMART_testY = test_[['srch_id', 'booking_bool', 'click_bool']] LambdaMART_test_qids = LambdaMART_testX.index #LambdaMART predictions Lambda_pred = model.predict(LambdaMART_testX) print('Random ranking: ', metric.calc_mean_random(LambdaMART_test_qids, LambdaMART_testY)) print('Our model: ', metric.calc_mean(LambdaMART_test_qids, LambdaMART_testY, Lambda_pred)) #old way, probably not correct for LambdaMART output_LM_out = model.predict(test[m2_rnn]) result = test[['srch_id', 'booking_bool', 'click_bool']] result = result.assign(pred=output_LM_out)
# In[5]: model = LambdaMART(metric=metric, max_depth = 4, n_estimators=450, learning_rate=.04, verbose=1, max_features = 25, min_samples_split = 1000, min_samples_leaf = 200, max_leaf_nodes = 20) model.fit(x_train, y_train, qids_train, monitor=monitor) # In[ ]: prediction = model.predict(x_test) print ('Random ranking:', metric.calc_mean_random(qids_test, y_test)) print ('Our model:', metric.calc_mean(np.asarray(qids_test), np.asarray(y_test), prediction)) prediction_train = model.predict(x_train) print ('Train model:', metric.calc_mean(np.asarray(qids_train), np.asarray(y_train), prediction_train)) # In[ ]: #a = zip(model.feature_importances_, x_train.columns) #b = list() #for imp, name in a: # b.append((imp, name)) #sorted(b)