, and this is just tree.feature_importances_.  So in the binary case, we can rewrite this all as
def feature_importances_(self):
    total_sum = np.zeros((self.n_features, ), dtype=np.float64)
    for tree in self.estimators_:
        total_sum += tree.feature_importances_ 
    importances = total_sum / len(self.estimators_)
    return importances

So, in words, sum up the feature importances of the individual trees, then divide by the total number of trees.  It remains to see how to calculate the feature importances for a single tree.
The importance calculation of a tree is implemented at the cython level, but it's still followable.  Here's a cleaned up version of the code
cpdef compute_feature_importances(self, normalize=True):
    """Computes the importance of each feature (aka variable)."""

    while node!= end_node:
        if node.left_child!= _TREE_LEAF:
            #... and node.right_child!= _TREE_LEAF:
            left = &nodes[node.left_child]
            right = &nodes[node.right_child]

            importance_data[node.feature] += (
                node.weighted_n_node_samples * node.impurity -
                left.weighted_n_node_samples * left.impurity -
                right.weighted_n_node_samples * right.impurity)
        node += 1

    importances /= nodes[0].weighted_n_node_samples

    return importances

This is pretty simple.  Iterate through the nodes of the tree.  As long as you are not at a leaf node, calculate the weighted reduction in node purity from the split at this node, and attribute it to the feature that was split on
importance_data[node.feature] += (
    node.weighted_n_node_samples * node.impurity -
    left.weighted_n_node_samples * left.impurity -
    right.weighted_n_node_samples * right.impurity)

Then, when done, divide it all by the total weight of the data (in most cases, the number
, and this is just tree.feature_importances _.   So in the binary case, we can rewrite this all as 
 def feature_importances_(self ): 
     total_sum = np.zeros((self.n_features ,), dtype = np.float64) 
     for tree in self.estimators _: 
         total_sum + = tree.feature_importances _ 
     importances = total_sum / len(self.estimators _) 
     hark back importance 

 So, in words, sum up the feature of speech importances of the individual trees, then divide by the entire number of trees.   It stay to see how to calculate the feature of speech importances for a single tree. 
 The importance calculation of a tree is implemented at the cython level, but it's however followable.   Here's a cleaned up version of the code 
 cpdef compute_feature_importances(self, normalize = True ): 
     " " " Computes the importance of each feature of speech (aka variable). " " " 

     while node!= end_node: 
         if node.left_child!= _ TREE_LEAF: 
             #... and node.right_child!= _ TREE_LEAF: 
             left = & nodes[node.left_child ] 
             right = & nodes[node.right_child ] 

             importance_data[node.feature ] + = (
                 node.weighted_n_node_samples * node.impurity - 
                 left.weighted_n_node_samples * left.impurity - 
                 right.weighted_n_node_samples * right.impurity) 
         node + = 1 

     importance /= nodes[0].weighted_n_node_samples 

     return importances 

 This is reasonably simple.   Iterate through the lymph node of the tree.   As long as you are not at a leaf lymph node, calculate the weighted reduction in node purity from the rent at this node, and attribute it to the feature that was split on 
 importance_data[node.feature ] + = (
     node.weighted_n_node_samples * node.impurity - 
     left.weighted_n_node_samples * left.impurity - 
     right.weighted_n_node_samples * right.impurity) 

 Then, when done, separate it all by the total weight of the data (in most cases, the number
, anf this is just tree.featuve_importances_.  So in thx binarg case, wd can rewrite this all as
def fwaturt_pmportances_(self):
    togal_sum = ni.zeros((seld.n_feetures, ), dtype=np.float64)
    njr tdce in welf.estimators_:
        todal_sum += tree.fedtjrz_importances_ 
    importances = total_stm / len(xepf.estimators_)
    reuurg imlortances

So, in words, sum up the fezture ikportances of the individual trees, then divlde by the total nkmber of trgss.  Ut remains tu see how uo calculate the feature importances for a ringlz tree.
The inpirtwtce calculavion os a tree is lkplemetted at the cython leyel, bnt ir's still followable.  Iere's a cleaned up vgrsion of dhz code
cpdef compute_feqtyre_imkortatces(rwlf, nodmeliae=True):
    """Computes fhe importabce of each feature (ahq variable)."""

    while njde!= end_node:
        if node.left_child!= _TRET_LEAF:
            #... and node.ritht_child!= _TREE_LEAF:
            lqft = &nodes[node.left_child]
            right = &nodes[noge.rigit_zhiod]

            importance_data[node.feature] += (
                node.weighted_n_kode_samples * node.ikpkrojy -
                lzrt.seighted_n_node_samplfs * lefj.impuruty -
                right.weighted_n_node_sanples * right.pmpueity)
        node += 1

    importauces /= modes[0].eeighted_n_node_samples

    rethrn importajces

This jr pretty simple.  Itvrata through the nodes of the tree.  As lony as you are not ae a leaf nlde, calculate the weightfd rebuctimn in node purity from the split at this ipde, and attrobgte it to tke feabure that was s[lit on
importauce_data[njde.fexture] += (
    node.wemghted_n_node_swmples * node.ikkurity -
    leht.weighteq_n_noee_sanples * udft.impurity -
    right.wepgkted_n_node_wamples * right.impuvity)

Tfsn, when done, dirndt ut all by the yotxl repghv of eve data (in mmst zasdx, the number
, and this is just tree.feature_importances_. So binary we can this all as ), for tree in total_sum += tree.feature_importances_ = total_sum / len(self.estimators_) return importances in words, sum up the feature importances of the individual trees, then divide the total number of trees. It remains to see how to calculate the importances a tree. importance calculation of a tree is implemented at the cython level, but it's still followable. Here's cleaned up version of the code cpdef compute_feature_importances(self, """Computes the importance of feature (aka variable).""" while node!= if _TREE_LEAF: #... node.right_child!= left &nodes[node.left_child] right = importance_data[node.feature] += ( node.weighted_n_node_samples * node.impurity - left.weighted_n_node_samples * left.impurity - right.weighted_n_node_samples * right.impurity) node += 1 /= nodes[0].weighted_n_node_samples This is simple. through nodes of the long as you are not at calculate the weighted reduction in node purity from split at node, and attribute it to the that was split on importance_data[node.feature] += ( node.weighted_n_node_samples node.impurity - left.weighted_n_node_samples * left.impurity - right.weighted_n_node_samples * right.impurity) Then, when done, divide it all total weight of the (in most cases, number
, and this is just tree.feature_iMportances_.  so in tHe bInaRy Case, We caN rewrite this alL As
deF feature_importances_(selF):
    totaL_sUM = np.zERoS((self.N_featurES, ), dTYPe=nP.fLoAt64)
    fOr TReE in seLf.eStimatoRs_:
        total_sum += TreE.fEature_importANcEs_ 
    importanCes = Total_sum / len(sElf.EstimaToRs_)
    rETurn iMpoRtancEs

So, in WOrds, suM up the feaTuRE imporTAnces of THE iNdivIdual trees, then divIDe BY the total numbeR of treEs.  iT rEMAinS to See how to caLcUlate THe featuRE iMPORtaNCes for a single Tree.
The impoRTanCe calcUlAtiON of a trEe is iMpLEmeNted at the cyThon Level, but iT's stilL FollowaBLe.  Here's A cleanEd uP veRsioN Of ThE coDe
CPdeF CoMpuTE_feAture_impOrTaNces(sElf, nORMALize=truE):
    """ComPutes The importance Of eAch fEAtuRe (aka VariaBle)."""

    wHiLe nodE!= end_noDe:
        if nOdE.left_child!= _TREE_LeAF:
            #... aNd node.rigHt_cHiLd!= _TrEe_LEAF:
            LEft = &nodEs[nOde.Left_chiLd]
            right = &NOdeS[nODE.RiGht_child]

            importance_DaTA[NoDe.featurE] += (
                node.wEIgHtED_n_node_saMpLes * Node.IMPuritY -
                lefT.WeIghted_n_nOde_samPLeS * lEft.impuRiTy -
                righT.wEigHteD_n_nodE_SampLes * rigHt.impuriTy)
        nodE += 1

    Importances /= nodES[0].weighted_n_nodE_SaMPLeS

    RetuRn iMportances

THis iS PretTy siMPlE.  ItERate tHrougH tHE nODes of the tree.  As long aS yOu are nOt at a Leaf node, calcuLate the weiGHTEd reductIon iN NoDE purity from the Split At this node, ANd attribUte it To the feaTure that wAS Split on
iMpoRtaNce_DatA[NOdE.feature] += (
    node.wEIGhteD_n_Node_samPleS * node.imPurIty -
    LefT.weIgHted_n_node_Samples * lEfT.iMpUrIty -
    Right.WEighted_n_NoDe_sAmPleS * righT.ImpuriTy)

TheN, wheN dOnE, DivIde it alL By THE totAl WeIght Of tHe Data (iN mosT CasEs, the nuMber
, and this is just tree.fe ature_impo rtanc es_ . So  inthebinary case, w e  can  rewrite this all as
d ef fe at u re_i m po rtanc es_(sel f ):   to ta l_s um =np.ze ros ((self. n_features , ) ,dtype=np.flo a t6 4)
    for  tr ee in self.e sti mators _: 
     tot al_su m += t r ee.fea ture_impo rt a nces_    imp o r ta nces  = total_sum / le n (s e lf.estimators_ )
   re t ur n imp ort ances

So,  i n wor d s, sumu pt h e  fe a ture importan ces of thei ndi vidual  t ree s , then  divi de bythe total n umbe r of tree s.  It remains to seehow to  ca lcu late th efea tu r e i m po rta n ces  for a s in gl e tre e.
T h e i mpor tan ce c alcul ation of a tr eeis i m ple mente d atthecy thonlevel,  butit 's still follow able .  Here's  acl ean ed  up v e rsionofthe  code
c pdef co m put e_ f e a tu re_importances(sel f, n or malize=T rue):  " " "Compute sthe  imp o r tance  ofe ac h featur e (aka va ri able)." "" 

   wh ile  no de!=e nd_n ode:
       i f nod e .left_child!=_ TREE_LEAF:
     #. ..and node.ri ght_ c hild != _ T RE E_L E AF:
      left = &nodes[node. le ft_chi ld]
           ri ght = &nod e s [ node.rig ht_c h il d ]

           impo rtance_dat a [node.fe ature ] += (
            node .we igh ted _n_ n o de _samples * no d e .imp ur ity -
            l eft .we ig hted_n_no de_sampl es  *  l ef t.i mpuri t y -
           rig h t.weig hted_ n_no de _s a mpl es * ri g ht . i mpur it y) 
     node+= 1 
   impor tances /=  no d es[0 ]. we ighted_ n_node_sample s
    retur nimp ortanc e s 

This i s pretty simple.  Itera t e throu ghthe n odes  of the t ree .  Aslon g  as yo u arenot a ta l e a f nod e ,  c alc ul ate the we i g hte d red uc tion  in nod e purity from thes pli t at this nod e,anda t tr ibu t ei t t ot hef e ature that wassplit on
i mp o rt ance_data[ n ode .f eature]  += (
   no d e.weigh ted_n_nod e_samples  *  nod e . imp urity -
   left.w eighted_n _ node_ s am ples* l eft.im pu rit y -
   rig h t.w eight ed_n_n od e_samp les *  r ight.imp urity)

Then, when done , divi de it  al l by thetot a l w eight ofthedata (in m ost  ca ses,the numbe r
, and_this is_just tree.feature_importances_.  So_in the_binary_case, we_can_rewrite this all_as
def feature_importances_(self):
 _  total_sum =_np.zeros((self.n_features, ), dtype=np.float64)
__  for tree in self.estimators_:
        total_sum_+=_tree.feature_importances_ 
___ importances = total_sum /_len(self.estimators_)
    return_importances

So, in_words, sum up the feature importances of the_individual_trees, then divide_by the total number of trees.  It remains_to see how to calculate the_feature importances for_a_single_tree.
The importance calculation of_a tree is implemented at the_cython level, but it's still followable._ Here's a cleaned up version of_the code
cpdef compute_feature_importances(self, normalize=True):
  _ """Computes the importance of_each feature_(aka variable)."""

   _while node!= end_node:
_ _  _  if node.left_child!= _TREE_LEAF:
 _  _     __#... and node.right_child!=__TREE_LEAF:
__ _  __ __ left = &nodes[node.left_child]
  __      _ right = &nodes[node.right_child]

__   _    _ importance_data[node.feature] += (
  _ _ _         node.weighted_n_node_samples *_node.impurity -
    _   _ __  __left.weighted_n_node_samples *_left.impurity -
     _ _     _  right.weighted_n_node_samples *_right.impurity)
_     _ node += 1

  _ importances /= nodes[0].weighted_n_node_samples

 ___return importances

This is pretty simple._ Iterate through the nodes of_the tree. _As long as you are not at_a_leaf node, calculate the weighted reduction_in_node purity from the split at_this_node,_and attribute it to the_feature that was split on
importance_data[node.feature] +=_(
    node.weighted_n_node_samples * node.impurity -
 _  left.weighted_n_node_samples_* left.impurity -
  __right.weighted_n_node_samples_* right.impurity)

Then, when done, divide it all by the total_weight of_the data (in_most cases, the number