日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LGB 的 .feature_importance() 函数

發布時間:2025/3/15 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LGB 的 .feature_importance() 函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對于機器學習訓練來說,每一種特征對于機器學習訓練的模型的重要性可能是不一樣的,此時,這個函數就起到了作用。

下面是文檔

feature_importance(importance_type='split', iteration=None)
  • Get feature importances.
    Parameters:

    importance_type (string, optional (default=“split”))– How the importance is calculated. If “split”, result contains numbers of times the feature is used in a model. If “gain”, result contains total gains of splits which use the feature.

    iteration (int or None, optional (default=None)) – Limit number of iterations in the feature importance calculation. If None, if the best iteration exists, it is used; otherwise, all trees are used. If <= 0, all trees are used (no limits).

下面是一個py文件中的代碼樣例

for i, (train_ind, val_ind) in enumerate(kf.split(train)): # i 返回的是第幾折, train_ind 是訓練集, val_ind 是測試集print(f'Beginning fold {i}')train_data = lgb.Dataset(X.iloc[train_ind],label=y.iloc[train_ind])val_data = lgb.Dataset(X.iloc[val_ind],label=y.iloc[val_ind])model = lgb.train(params,train_data,num_boost_round=10000,valid_sets = [train_data, val_data],verbose_eval=100,early_stopping_rounds = 100)#Save both split and gain importances, averaged over 5 folds# 統計某種特征在該機器學習算法模型中使用過的次數(這里求的是5次訓練的平均值)feats['importance_split'] += model.feature_importance()/5# 統計某種特征在整個.py文件中使用的次數(這里求的是5次訓練的平均值)feats['importance_gain'] += model.feature_importance(importance_type='gain')/5

總結

以上是生活随笔為你收集整理的LGB 的 .feature_importance() 函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。