xgboost python分类_XGBoost多分类预测

import pandas as pd

from sklearn.model_selection import train_test_split

from xgboost.sklearn import XGBClassifier

from sklearn.metrics import classification_report

from sklearn.metrics import f1_score, precision_score, recall_score

from sklearn.externals import joblib # 将模型导出所需包

def get_cust_age_stage(birth_year):

"""根据出生年份获取年龄段"""

age_stage = []

for i in range(len(birth_year)):

if int(birth_year[i]) == 0:

age_stage.append("未知")

elif int(birth_year[i]) < 1960:

age_stage.append("60前")

elif int(birth_year[i]) < 1970:

age_stage.append("60后")

elif int(birth_year[i]) < 1980:

age_stage.append("70后")

elif int(birth_year[i]) < 1990:

age_stage.append("80后")

elif int(birth_year[i]) < 2000:

age_stage.append("90后")

elif int(birth_year[i]) >= 2000:

age_stage.append("00后")

else:

age_stage.append("未知")

return age_stage

def get_top5_onehot(data):

"""对c字段排名top5的进行one hot"""

# 获取top5的值

c_top5_counts = data['c'].value_counts()[:5]

c_top5_names = list(c_top5_counts.keys())

# 进行one-hot编码,只保留top5的列

c_one_hot = pd.get_dummies(data['c'])

c_top5 = c_one_hot[

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值