99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁大數(shù)據(jù)時代怎么理解隨機(jī)森里中feature importance-特征重要性?
怎么理解隨機(jī)森里中feature importance-特征重要性?
2020-07-22
收藏

feature importance,根據(jù)含義就能理解,也就是特征重要性,在預(yù)測建模項目中起著非常重要作用,能夠提供對數(shù)據(jù)、模型的見解,和如何進(jìn)行降維和選擇特征,并以此來提高預(yù)測模型的的效率和有效性。今天小編為大家?guī)淼氖侨绾卫斫?a href='/map/suijisenlin/' style='color:#000;font-size:inherit;'>隨機(jī)森林中的feature importance,希望對大家有所幫助。

一、簡單了解feature importance

實際情況中,一個數(shù)據(jù)集中往往包含數(shù)以萬計個特征,如何在其中選擇出,結(jié)果影響最大的幾個特征,并通過這種方法縮減建立模型時的特征數(shù),這是我們最為關(guān)心的問題。今天要介紹的是:用隨機(jī)森林來對進(jìn)行特征篩選。

隨機(jī)森林進(jìn)行特征重要性評估的思想其實非常簡單,簡單來說,就是觀察每個特征隨機(jī)森林中的每顆樹上做了多少貢獻(xiàn),然后取平均值,最后對比特征之間的貢獻(xiàn)大小。

總結(jié)一下就是:特征重要性是指,在全部單顆樹上此特征重要性的一個平均值,而單顆樹上特征重要性計算方法事:根據(jù)該特征進(jìn)行分裂后平方損失的減少量的求和。

二、feature importance評分作用

1.特征重要性分可以凸顯出特征與目標(biāo)的相關(guān)相關(guān)程度,能夠幫助我們了解數(shù)據(jù)集

2.特征重要性得分可以幫助了解模型

特征重要性得分通常是通過數(shù)據(jù)集擬合出的預(yù)測模型計算的。查看重要性得分能夠洞悉此特定模型,以及知道在進(jìn)行預(yù)測時特征的重要程度。

3.特征重要性能夠用于改進(jìn)預(yù)測模型

我們可以通過特征重要性得分來選擇要刪除的特征(即得分最低的特征)或者需要保留的特征(即得分最高的特征)。這其實是一種特征選擇,能夠簡化正在建模的問題,加快建模過程,在某些情況下,還能夠改善模型的性能。

三、python實現(xiàn)隨機(jī)森林feature importances


import xlrd
import csv
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.interpolate import spline  
#設(shè)置路徑
path='/Users/kqq/Documents/postgraduate/煙葉原始光譜2017.4.7數(shù)字產(chǎn)地.csv'
#讀取文件
df = pd.read_csv(path, header = 0)
 
#df.info()
 
#訓(xùn)練隨機(jī)森林模型
from sklearn.cross_validation import train_test_split
from sklearn.ensemble import RandomForestClassifier
x, y = df.iloc[:, 1:].values, df.iloc[:, 0].values
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, random_state = 0)
feat_labels = df.columns[1:]
forest = RandomForestClassifier(n_estimators=10000, random_state=0, n_jobs=-1)
forest.fit(x_train, y_train)
 
 
#打印特征重要性評分
importances = forest.feature_importances_
#indices = np.argsort(importances)[::-1]
imp=[]
for f in range(x_train.shape[1]):
    print(f + 1, feat_labels[f], importances[f])
    
 
 
#將打印的重要性評分copy到featureScore.xlsx中;plot特征重要性
#設(shè)置路徑
path='/Users/kqq/Documents/postgraduate/實驗分析圖/featureScore.xlsx'
#打開文件
myBook=xlrd.open_workbook(path)
#查詢工作表
sheet_1_by_index=myBook.sheet_by_index(0)
data=[]
for i in range(0,sheet_1_by_index.nrows):
    data.append(sheet_1_by_index.row_values(i))   
data=np.array(data)
X=data[:1,].ravel()
y=data[1:,]
plt.figure(1,figsize=(8, 4))
i=0
print(len(y))
while i  


相信讀完上文,你對算法已經(jīng)有了全面認(rèn)識。若想進(jìn)一步探索機(jī)器學(xué)習(xí)的前沿知識,強(qiáng)烈推薦機(jī)器學(xué)習(xí)之半監(jiān)督學(xué)習(xí)課程。

學(xué)習(xí)入口:https://edu.cda.cn/goods/show/3826?targetId=6730&preview=0
涵蓋核心算法,結(jié)合多領(lǐng)域?qū)崙?zhàn)案例,還會持續(xù)更新,無論是新手入門還是高手進(jìn)階都很合適。趕緊點擊鏈接開啟學(xué)習(xí)吧!

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時表示是新驗證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }