python xgboost输出变量重要性_xgboost特征重要性指标: weight, gain, cover

本文介绍了如何使用Python的xgboost库获取特征重要性,并通过实例解释了'weight', 'gain', 'cover', 'total_gain', 'total_cover'这五个指标的含义。通过训练一个简单的二分类模型,展示了每个指标在实际模型中的应用,帮助理解特征重要性的计算和作用。" 117070605,9919043,Java RSA与AES加密实战指南,"['加密解密', 'Java安全', 'RSA算法', 'AES算法', '数据加密']
摘要由CSDN通过智能技术生成

官方解释

Python中的xgboost可以通过get_fscore获取特征重要性,先看看官方对于这个方法的说明:

get_score(fmap=’’, importance_type=‘weight’)

Get feature importance of each feature. Importance type can be defined as:

‘weight’: the number of times a feature is used to split the data across all trees.

‘gain’: the average gain across all splits the feature is used in.

‘cover’: the average coverage across all splits the feature is used in.

‘total_gain’: the total gain across all splits the feature is used in.

‘total_cover’: the total coverage across all splits the feature is used in.

看释义不直观,下面通过训练一个简单的模型,输出这些重要性指标,再结合释义进行解释。

代码实践

首先构造10个样例的样本,每个样例有两维特征,标签为0或1,二分类问题:

import numpy as np

sample_num = 10

feature_num = 2

np.random.seed(0)

data = np.random.randn(sample_num, feature_num)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值