深度学习笔记--XGBOOST算法应用ctr预估模型

赛题地址:https://tianchi.aliyun.com/competition/myScore.htm?spm=5176.11165268.5678.7.78e3563388Unvl&raceId=231688
代码如下

import re
import pandas as pd
import numpy as np
import json
import lightgbm as lgb
from sklearn.model_selection import StratifiedKFold
from sklearn.metrics import f1_score
from sklearn.externals import joblib
from sklearn import svm
import math
from sklearn.model_selection import GridSearchCV
import xgboost as xgb
from xgboost import plot_importance

def get_query_predictions_values(x, index):
    x = json.loads(x) 
    length = len(x)
    if length <= index:
        return 0
    else:
        x = x.values()
        x = [float(value) for value in x]
        x = sorted(x)
        return x[index]

def get_query_prediction_keys(x):
    x = json.loads(x) 
    x = x.keys()
    x = [remove_cha(value) for value in x]
    
    return ' '.join(x)

def get_max_query_prediction(x):
    x = json.loads(x)
    if len(x) == 0:
        return 0
    x = x.values()
    return max(x)

def remove_cha(x):
     
    x = re.sub('[\s+\.\!\/_,$%^*(+\"\')]+|[+——()?【】“”!,。?、~@#¥%……&*()]+', "", str(x))
    x = x.replace('2C', '')
    return x


def len_title_in_query(title, query):
    query = query.split(' ')
    if len(query) == 0:
        return 0
    l = 0
    for value in query:
        #print(value)
        if value.find(title) >= 0:
            #print(l)
            l += 1
    # print(l)
    return l

def is_prefix_in_title(prefix, title):
    #print(prefix)

    #print(title)
    return title.find('prefix')



train_data = pd.read_table('./data/oppo_round1_train_20180929.txt', 
        names= ['prefix','query_prediction','title','tag','label'], header= None, encoding='utf-8').astype(str)
val_data = pd.read_table('./data/oppo_round1_vali_20180929.txt', 
        names = ['prefix','query_prediction','title','tag','label
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值