pyspark GBTRegressor 特征重要度 及排序


GBTRegressor  模型評估指標和特征重要度分析

官方文檔:https://spark.apache.org/docs/2.2.0/api/python/_modules/pyspark/ml/regression.html

 

和隨機森林類似,訓練好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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM