0
我得到decision tree
爲churn
數據集使用J48()
函數從RWeka
包。樹很大,因此我無法看到整棵樹。我想輸出它在一個文本文件,但格式正在改變。我怎樣才能保存它保存樹格式。在文本文件中輸出J48樹R
save(m2,file="thisexample.txt", ascii=TRUE)
m2
是在我存儲J48
樹輸出的dataframe
。
我得到decision tree
爲churn
數據集使用J48()
函數從RWeka
包。樹很大,因此我無法看到整棵樹。我想輸出它在一個文本文件,但格式正在改變。我怎樣才能保存它保存樹格式。在文本文件中輸出J48樹R
save(m2,file="thisexample.txt", ascii=TRUE)
m2
是在我存儲J48
樹輸出的dataframe
。
I.使用iris
數據集的示例使用RWeka
的J48()
函數。
library(RWeka)
result = J48(Species~.,data=iris)
result
# J48 pruned tree
# ------------------
# Petal.Width <= 0.6: setosa (50.0)
# Petal.Width > 0.6
# | Petal.Width <= 1.7
# | | Petal.Length <= 4.9: versicolor (48.0/1.0)
# | | Petal.Length > 4.9
# | | | Petal.Width <= 1.5: virginica (3.0)
# | | | Petal.Width > 1.5: versicolor (3.0/1.0)
# | Petal.Width > 1.7: virginica (46.0/1.0)
# Number of Leaves : 5
# Size of the tree : 9
二,使用sink()
函數將其寫入文本文件中
sink("result.txt")
print (result)
sink()
三,打開result.txt
保存在您當前的工作目錄中。
作爲文本文件?那究竟是什麼樣子?這將有助於如果你的例子[可重現](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)與一些示例輸入,所以我們可以看到你是什麼這樣做。 – MrFlick
我只是想要一個格式,我可以打開並看到樹形結構,因爲數據框中的輸出太大而無法進入R中的單個屏幕。在此鏈接的第4頁上,我的輸出也看起來像它 - https: //www.erpublication.org/admin/vol_issue1/upload%20Image/IJETR032129.pdf – Joe