TensorFlow随机森林绘图错误

huangapple go评论78阅读模式
英文:

tensorflow random forest ploting errors

问题

在拟合训练数据后,您可以使用以下代码来可视化模型,但未显示任何内容:

tfdf.model_plotter.plot_model_in_colab(rf, tree_idx=0, max_depth=3)

关于此问题,您可以尝试以下建议:

  1. 确保您的Jupyter环境支持在Colab中显示图形。有时候,在某些环境中,图形可能无法正确显示。您可以尝试在不同的Jupyter笔记本或Colab中运行此代码,看是否能够正常显示图形。

  2. 检查模型是否已正确训练。确保模型 rf 已经在前面的代码中成功拟合了训练数据。

  3. 考虑更改 tree_idxmax_depth 参数的值,看看是否会影响图形的显示。有时候,选择不同的参数值可以改善可视化结果。

  4. 检查依赖项是否正确安装。根据您的描述,似乎依赖项已正确安装,但仍然可以再次确认。

这些建议可以帮助您解决问题并正确显示模型可视化。

英文:

running jupyter on anaconda mac/m2

after fitting the training data

rf = tfdf.keras.RandomForestModel(task = tfdf.keras.Task.REGRESSION)
rf.compile(metrics=["mse"])

rf.fit(x=train_ds)

i want to vizualise the model with the following code, but nothing is displayed

tfdf.model_plotter.plot_model_in_colab(rf, tree_idx=0, max_depth=3)

can i please have a suggestion or recommendation about what to do?

yep!(i tried chatgpt) it wrote the same code several times or a variation and still nothing.

according to chatgpt i have all the dependences installed

答案1

得分: 1

TF-DF的作者在此。

不幸的是,仅在Colab中才能使用TF-DF进行交互式绘图,而在IPython中无法使用,因为它们具有稍微不同的JavaScript集成。目前,您有两个选项:

  1. 使用非交互式文本绘图:
> print(model_1.make_inspector().extract_tree(1))
(bill_depth_mm >= 16.350000381469727; miss=True, score=0.4877108931541443)
    ├─(pos)─ (bill_length_mm >= 43.05000305175781; miss=True, score=0.4372641444206238)
    │        ├─(pos)─ (body_mass_g >= 4125.0; miss=True, score=0.52157062292099)
    │        │        ├─(pos)─ (flipper_length_mm >= 199.01458740234375; miss=True, score=0.5047621130943298)
    │        │        │    ...
    │        │        └─(neg)─ ProbabilityValue([0.0, 0.0, 1.0],n=38.0) (idx=5)
    │        └─(neg)─ (bill_depth_mm >= 17.450000762939453; miss=False, score=0.015847451984882355)
    │                 ├─(pos)─ ProbabilityValue([1.0, 0.0, 0.0],n=68.0) (idx=4)
    │                 └─(neg)─ (bill_length_mm >= 38.900001525878906; miss=True, score=0.0711795762181282)
    │                      ...
    └─(neg)─ (body_mass_g >= 3750.0; miss=True, score=0.20150887966156006)
             ├─(pos)─ ProbabilityValue([0.0, 1.0, 0.0],n=93.0) (idx=1)
             └─(neg)─ ProbabilityValue([1.0, 0.0, 0.0],n=5.0) (idx=0)
  1. 如果您想要美观的可视化图表,具有许多选项和大量信息,您可以使用 dtreeviz。TensorFlow网站上有一份 教程 详细解释了如何在TF-DF中使用它。

  2. 自行提取TF-DF生成的HTML并在兼容的查看器中使用:

html = tfdf.model_plotter.plot_model(rf, tree_idx=0, max_depth=3)
英文:

TF-DF author here.

Unfortunately, interactive plotting with TF-DF only works in Colab, not in IPython, since the two have slightly different Javascript integrations. Currently, you have two options:

  1. Use non-interactive text plots:
> print(model_1.make_inspector().extract_tree(1))
(bill_depth_mm >= 16.350000381469727; miss=True, score=0.4877108931541443)
    ├─(pos)─ (bill_length_mm >= 43.05000305175781; miss=True, score=0.4372641444206238)
    │        ├─(pos)─ (body_mass_g >= 4125.0; miss=True, score=0.52157062292099)
    │        │        ├─(pos)─ (flipper_length_mm >= 199.01458740234375; miss=True, score=0.5047621130943298)
    │        │        │    ...
    │        │        └─(neg)─ ProbabilityValue([0.0, 0.0, 1.0],n=38.0) (idx=5)
    │        └─(neg)─ (bill_depth_mm >= 17.450000762939453; miss=False, score=0.015847451984882355)
    │                 ├─(pos)─ ProbabilityValue([1.0, 0.0, 0.0],n=68.0) (idx=4)
    │                 └─(neg)─ (bill_length_mm >= 38.900001525878906; miss=True, score=0.0711795762181282)
    │                      ...
    └─(neg)─ (body_mass_g >= 3750.0; miss=True, score=0.20150887966156006)
             ├─(pos)─ ProbabilityValue([0.0, 1.0, 0.0],n=93.0) (idx=1)
             └─(neg)─ ProbabilityValue([1.0, 0.0, 0.0],n=5.0) (idx=0)
  1. If you want beautiful visualizations with lots of options and lots of information, you can use dtreeviz. There is a tutorial on the TensorFlow website that explains in detail how to use it with TF-DF

  2. Extract the HTML that TF-DF produces yourself and use it in a compatible viewer:

html = tfdf.model_plotter.plot_model(rf, tree_idx=0, max_depth=3)

huangapple
  • 本文由 发表于 2023年7月3日 18:40:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603969.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定