英文:
tensorflow random forest ploting errors
问题
在拟合训练数据后,您可以使用以下代码来可视化模型,但未显示任何内容:
tfdf.model_plotter.plot_model_in_colab(rf, tree_idx=0, max_depth=3)
关于此问题,您可以尝试以下建议:
-
确保您的Jupyter环境支持在Colab中显示图形。有时候,在某些环境中,图形可能无法正确显示。您可以尝试在不同的Jupyter笔记本或Colab中运行此代码,看是否能够正常显示图形。
-
检查模型是否已正确训练。确保模型
rf
已经在前面的代码中成功拟合了训练数据。 -
考虑更改
tree_idx
和max_depth
参数的值,看看是否会影响图形的显示。有时候,选择不同的参数值可以改善可视化结果。 -
检查依赖项是否正确安装。根据您的描述,似乎依赖项已正确安装,但仍然可以再次确认。
这些建议可以帮助您解决问题并正确显示模型可视化。
英文:
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集成。目前,您有两个选项:
- 使用非交互式文本绘图:
> 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)
-
如果您想要美观的可视化图表,具有许多选项和大量信息,您可以使用 dtreeviz。TensorFlow网站上有一份 教程 详细解释了如何在TF-DF中使用它。
-
自行提取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:
- 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)
-
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
-
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论