XGBoost调参

在这里插入图片描述

import pandas as pd
import numpy as np
from sklearn.metrics import mean_absolute_error,make_scorer
import xgboost as xgb
from sklearn.model_selection import GridSearchCV
import warnings
warnings.filterwarnings('ignore')

train=r'C:\Users\10991\Desktop\kaggle\baoxian_train.csv'
test=r'C:\Users\10991\Desktop\kaggle\baoxian_test.csv'
train=pd.read_csv(train)

train['log_loss']=np.log(train['loss'])
features=[x for x in train.columns if x not in ['loss','id','log_loss']]
cat_features=[x for x in train.select_dtypes(include=['object']).columns if x not in ['loss','id','log_loss']]
num_features=[x for x in train.select_dtypes(exclude=['object']).columns if x not in ['loss','id','log_loss']]
print(len(cat_features))
print(len(num_features))
ntrain=train.shape[0]
train_x=train[features]
train_y=train['log_loss']
for c in range(len(cat_features)):
    train_x[cat_features[c]]=train_x[cat_features[c]].astype('category').cat.codes
print(train_x.shape)
print(train_y.shape

def xg_eval_mae(yhat,dtrain):  #平均绝对误差来衡量效果
    y=dtrain.get_label()
    return &#
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值