如何将多个形状图保存到 html 中?

DN1*_*DN1 5 python plot plotly shap

我有使用该shap包绘制的机器学习结果。特别是,我绘制了交互式形状力图和静态形状热图。

目前,我将形状力图保存为 html 文件,但我想将形状热图添加到交互式力图下方的 html 中。

此处显示了交互式形状力图的示例:https://shap.readthedocs.io/en/latest/example_notebooks/tabular_examples/tree_based_models/Force%20Plot%20Colors.html(下面第三张图,交互式图)

形状热图的示例如下:https ://shap.readthedocs.io/en/latest/example_notebooks/api_examples/plots/heatmap.html

我目前对这些图的编码方式是:

import shap

model = RandomForestRegressor()
explainer = shap.TreeExplainer(model)
shap_values = explainer(X)
select = range(8)
features = X.iloc[select]
features_display = X.loc[features.index]

#Create force plot and save it as html:

output_of_force_plot = shap.force_plot(explainer.expected_value, shap_values[:500,:], 
                                        X.iloc[:500,:], features_display, show=False)

file ='force_plot.html'
shap.save_html(file, output_of_force_plot)


#Create static heat map:

shap_heatmap = shap.plots.heatmap(shap_values, max_display=8, show=False)
Run Code Online (Sandbox Code Playgroud)

目前,要将其添加shap_heatmap到与我相同的html中,我已经尝试使用plotly( Plotly saving multipleplots into a single htmloutput_of_force_plot )类似问题的答案,但它不起作用:

import plotly
with open('p_graph.html', 'a') as f:
    shap.save_html(file, output_of_force_plot, full_html=False)
    f.write(shap_heatmap.to_html(full_html=False))

AttributeError: 'NoneType' object has no attribute 'to_html'
Run Code Online (Sandbox Code Playgroud)

有没有办法修改这个plotly示例以适用于我的 shap html?或者我可以用另一种方式将我的两个数字合并到一个 html 中?我只希望交互式图保持交互式,然后在该交互式图下方显示形状热图。不幸的是,我无法提供示例数据来绘制这种情况下的精确图。