pyspark GBTRegressor 特征重要度 及排序

2021-04-07 13:25

阅读:404

标签:com   meta   mode   net   end   pen   随机森林   lam   bsp   

和随机森林类似,模型评估指标和特征重要度分析

训练好model 可用如下代码打印特征以及重要度排序

#打印特征索引及其重要度
features_important = model.featureImportances
print(features_important)

#获取各个特征在模型中的重要性并按照权重倒序打印
ks = list(features_important.indices)
vs = list(features_important.toArray())

features_important = tuple(features_important)
print(len(features_important))


name_index = train.schema["features"].metadata["ml_attr"]["attrs"]


index_im = zip(ks, vs)
names = []
idxs = []
 
fea_num = 0

for it in name_index[‘numeric‘]:
    names.append(it[‘name‘])
    idxs.append(it[‘idx‘])
    fea_num += 1
    
print (fea_num)

d = zip(names, idxs)
p = zip(index_im, d)
 
kv = {}
for fir, sec in p:
    kv[sec[0]] = fir[1]
    fea_num += 1
print(len(kv))
print (sorted(kv.items(), key=lambda el: el[1], reverse=True))

  

参考链接

https://blog.csdn.net/zx8167107/article/details/101709245?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param

 

https://blog.csdn.net/qq_23860475/article/details/90766237

pyspark GBTRegressor 特征重要度 及排序

标签:com   meta   mode   net   end   pen   随机森林   lam   bsp   

原文地址:https://www.cnblogs.com/Allen-rg/p/13390083.html


评论


亲,登录后才可以留言!