Papermill + Scrapbook:是否可以在Papermill笔记本中重新书写文本?

时间:2019-04-24 14:12:45

标签: jupyter-notebook papermill

我使用Papermill笔记本(“ orchester_notebook”)多次启动带有不同参数集的“ training_notebook”。

对于每组参数,将保存一个带有打印结果(文本)和图形的新“ result_notebook”。

我知道如何在“ orchester笔记本”中的“ result_notebook”中显示图形

但是我也希望在“ orchester_notebook”中显示文本结果(准确性,分类报告等)。

您知道是否可以通过剪贴簿重新显示文字吗?

我的下面的代码:

orchestrer_notebook

  checkUsername(tag: string) {
    console.log('Checking Username: ' + username);
    return  this.afs.collection('usernames', ref => ref.where('username', '==', tag)).valueChanges();
  }

training_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')

2 个答案:

答案 0 :(得分:1)

我在doc中错过了这一点:

"""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')

答案 1 :(得分:0)

上面的答案对我不起作用,我读了other doc part,下面的解决方案对我有用:

在培训笔记本中:

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笔记本中:

out.reglue("media_as_text_only")