2015-11-11 3 views
6

Kann jemand die Zahlen berechnen? In der Dokumentation heißt es, dass diese Funktion "Feature-Wichtigkeit jeder Funktion erhalten", aber es gibt keine Erklärung, wie die Ergebnisse zu interpretieren sind.Was macht get_fscore() eines xgboost ML-Modells?

+1

nicht sicher, aber der Code und die Methode selbst ist auf GitHub hier: https://github.com/dmlc/xgboost/blob/master/python-package /xgboost/core.py – scrineym

+1

Danke. Wenn Sie den Code durchlaufen, können Sie sehen, dass es sich um eine Zählung handelt, wie oft dieses Feature im Entscheidungsbaum angezeigt wird. –

Antwort

3

Dies ist eine Metrik, die einfach zusammenfasst, wie oft jede Funktion aufgeteilt wird. Es ist analog zur Frequenzmetrik in der R-Version. https://cran.r-project.org/web/packages/xgboost/xgboost.pdf

Es ist etwa so einfach eine Funktion Wichtigkeit Metrik wie Sie bekommen können.

, d. H. Wie oft wurde diese Variable geteilt?

Der Code für diese Methode zeigt, dass das Vorhandensein eines bestimmten Features in allen Bäumen einfach hinzugefügt wird.

[hier .. https://github.com/dmlc/xgboost/blob/master/python-package/xgboost/core.py#L953][1]

def get_fscore(self, fmap=''): 
    """Get feature importance of each feature. 
    Parameters 
    ---------- 
    fmap: str (optional) 
     The name of feature map file 
    """ 
    trees = self.get_dump(fmap) ## dump all the trees to text 
    fmap = {}      
    for tree in trees:    ## loop through the trees 
     for line in tree.split('\n'):  # text processing 
      arr = line.split('[') 
      if len(arr) == 1:    # text processing 
       continue 
      fid = arr[1].split(']')[0] # text processing 
      fid = fid.split('<')[0]  # split on the greater/less(find variable name) 

      if fid not in fmap: # if the feature id hasn't been seen yet 
       fmap[fid] = 1 # add it 
      else: 
       fmap[fid] += 1 # else increment it 
    return fmap     # return the fmap, which has the counts of each time a variable was split on