def tune_entropy_threshold(self, n=5, depth=6, plot_debug=False):
"""
Compute mean optimal entropy based on L-curve elbow method.
"""
e_arr = []
for i in range(n):
var = Tree(self, rho=.5, depth=depth)
e_arr += [pair + [i] for pair in var.entropy_gain_evol]
var.domain_splits_plots(subpath='%s/'%i)
entropy_evol = pd.DataFrame(e_arr, columns=['depth', 'entropy', 'tree'])
entropy_evol = entropy_evol.groupby(['tree', 'depth'])[['entropy']].mean().reset_index().pivot(columns='tree', index='depth', values='entropy').fillna(0)
entropy_elbow_cand = entropy_evol.apply(lambda x: opt_L_curve(np.array(x.index), np.array(x)))
avg_opt_entropy = entropy_elbow_cand.mean()
if plot_debug:
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111)
entropy_evol.plot(ax=ax, kind='line', alpha=.6, lw=3., title='Avg. Opt. Entropy = %.2f'%avg_opt_entropy)
plt.savefig('evol.png', format='png')
plt.close()
return avg_opt_entropy
density_forest.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录