我使用Papermill笔记本("orchester_notebook")多次启动具有不同参数集的"training_notebook"。
对于每组参数,都会保存一个新的"result_notebook",其中包含打印的结果(文本)和图形。
我知道如何在我的"奥切斯特笔记本"中显示"result_notebook"中的图形
但我还希望在我的"orchester_notebook"中显示文本结果(准确性、分类报告,....)。
您知道是否可以通过剪贴簿重新粘贴文本吗?
我的代码如下:
orchestrer_notebook
import papermill as pm
import scrapbook as sb
experiment_dates = [20190101, 20190102]
features = 'my_features'
model = 'my_model'
parameters = dict({'experiment_dates' : experiment_dates, 'features' :
features, 'model' : model})
output_filename = str(experiment_dates) + '_' + features + model
pm.execute_notebook('Training.ipynb', output_filename + '.ipynb',
parameters=parameters)
out = sb.read_notebook(output_filename + '.ipynb')
out.reglue('figure')
training_notebook
import scrapbook as sb
# training
#...........
#............
fig, ax = plt.subplots()
ax.plot(data.index, data['mydata'], c='k', alpha=.5)
sb.glue('figure', fig, 'display')
print("this is my results") # how can I reglue this in orchestrer_notebook ?
我在文档中错过了这个:
"""glue example for recording data values"""
import scrapbook as sb
sb.glue("hello", "world") # this answers my need to reglue text
sb.glue("number", 123)
sb.glue("some_list", [1, 3, 5])
sb.glue("some_dict", {"a": 1, "b": 2})
sb.glue("non_json", df, 'arrow')
上面的答案对我不起作用,我阅读了另一个文档部分,以下解决方案对我有用:
在培训笔记本中:
sb.glue("media_as_text_only",
media_obj,
encoder='display',
display=('text/plain',) # This passes [text/plain] to format_display_data's include argument
)
在Orchetrer notebook中:
out.reglue("media_as_text_only")