我正在训练一个基于Kaggle心脏病数据的决策树模型。
由于我也在使用 10 倍 CV 构建其他模型,因此我尝试使用带有 rpart 方法的 caret 包来构建树。然而,情节结果很奇怪,因为“铊”应该是一个因素。为什么显示“thaliumnormal <0.5”?这是否意味着如果“铊”==正常“然后走左边的路线“是”,否则走右边的路线“否”?
非常感谢!
编辑:我很抱歉没有提供足够的背景信息,这似乎引起了一些混乱。“铊”是一个变量,代表一种用于检测冠状动脉狭窄(又名狭窄)的技术。它是一个具有三个级别(正常、固定缺陷、可逆缺陷)的因素。
此外,我想让图表更具可读性,例如代替“thliumnormal < 0.5”,它应该类似于“thlium = normal”。我可以通过直接使用 rpart 来实现这个目标(见下文)。
但是,您可能已经注意到树是不同的,尽管我使用了带有 caret rpart CV 10 折的推荐 cp 值(请参阅下面的代码)。
我了解这两个包可能会导致一些差异。理想情况下,我可以使用插入符号和方法 rpart 来构建树,以便它与插入符号中构建的其他模型对齐。有谁知道我如何使用 caret rpart 构建的树模型的绘图标签更容易理解?
This is the output of the code below
I was playing around with list() and [] to combine strings selected from the column names. Then I noticed some peculiar behaviors (shown below). Could someone please explain why Python interpret list() + [] OR [] + list() differently?
I tried to search what's the difference between list() and [], but none of the answers resolved my confusion.
# below is the output for census_df.columns
Index(['SUMLEV', 'REGION', 'DIVISION', 'STATE', 'COUNTY', 'STNAME', 'CTYNAME', …
Run Code Online (Sandbox Code Playgroud)