@@ -1825,9 +1825,7 @@ def _MTRF(self,x_continuous,x_categorical,y,n_estimators=100,**kwargs):
1825
1825
for i in range (n_estimators ):
1826
1826
self ._copy_tree_from_sklearn_tree (tmp_metatree_list [i ],randomforest .estimators_ [i ].tree_ , 0 )
1827
1827
1828
- print (f'before: { len (tmp_metatree_list )} ' )
1829
1828
tmp_metatree_list ,tmp_metatree_prob_vec = self ._marge_metatrees (tmp_metatree_list ,tmp_metatree_prob_vec )
1830
- print (f'after: { len (tmp_metatree_list )} ' )
1831
1829
1832
1830
log_metatree_posteriors = np .log (tmp_metatree_prob_vec )
1833
1831
if self .c_dim_continuous > 0 and self .c_dim_categorical > 0 :
@@ -1846,13 +1844,18 @@ def _MTRF(self,x_continuous,x_categorical,y,n_estimators=100,**kwargs):
1846
1844
tmp_metatree_prob_vec [:] /= tmp_metatree_prob_vec .sum ()
1847
1845
return tmp_metatree_list ,tmp_metatree_prob_vec
1848
1846
1849
- def _given_MT (self ,x ,y ):
1847
+ def _given_MT (self ,x_continuous , x_categorical ,y ):
1850
1848
"""make metatrees
1851
1849
1852
1850
Parameters
1853
1851
----------
1854
- x : numpy ndarray
1855
- values of explanatory variables whose dtype is int
1852
+ x_continuous : numpy ndarray, optional
1853
+ 2 dimensional float array whose size is ``(sample_size,c_dim_continuous)``,
1854
+ by default None.
1855
+ x_categorical : numpy ndarray, optional
1856
+ 2 dimensional int array whose size is ``(sample_size,c_dim_categorical)``,
1857
+ by default None. Each element x[i,j] must satisfy
1858
+ 0 <= x[i,j] < self.c_num_children_vec[self.c_dim_continuous+i].
1856
1859
y : numpy ndarray
1857
1860
values of objective variable whose dtype may be int or float
1858
1861
@@ -1865,9 +1868,18 @@ def _given_MT(self,x,y):
1865
1868
if not self .hn_metatree_list :
1866
1869
raise (ParameterFormatError ("given_MT is supported only when len(self.hn_metatree_list) > 0." ))
1867
1870
log_metatree_posteriors = np .log (self .hn_metatree_prob_vec )
1868
- for i ,metatree in enumerate (self .hn_metatree_list ):
1869
- for j in range (x .shape [0 ]):
1870
- log_metatree_posteriors [i ] += np .log (self ._update_posterior_recursion (metatree ,x [j ],y [j ]))
1871
+ if self .c_dim_continuous > 0 and self .c_dim_categorical > 0 :
1872
+ for i ,metatree in enumerate (self .hn_metatree_list ):
1873
+ for j in range (y .shape [0 ]):
1874
+ log_metatree_posteriors [i ] += np .log (self ._update_posterior_recursion (metatree ,x_continuous [j ],x_categorical [j ],y [j ]))
1875
+ elif self .c_dim_continuous > 0 :
1876
+ for i ,metatree in enumerate (self .hn_metatree_list ):
1877
+ for j in range (y .shape [0 ]):
1878
+ log_metatree_posteriors [i ] += np .log (self ._update_posterior_recursion (metatree ,x_continuous [j ],None ,y [j ]))
1879
+ else :
1880
+ for i ,metatree in enumerate (self .hn_metatree_list ):
1881
+ for j in range (y .shape [0 ]):
1882
+ log_metatree_posteriors [i ] += np .log (self ._update_posterior_recursion (metatree ,None ,x_categorical [j ],y [j ]))
1871
1883
self .hn_metatree_prob_vec [:] = np .exp (log_metatree_posteriors - log_metatree_posteriors .max ())
1872
1884
self .hn_metatree_prob_vec [:] /= self .hn_metatree_prob_vec .sum ()
1873
1885
return self .hn_metatree_list ,self .hn_metatree_prob_vec
0 commit comments