在 R 中将 J48 决策树输出到文本文件

我使用 RWeka 包中的 J48() 函数,已经得到了 churn 数据集的 decision tree。由于树非常大,我无法看到整个树。我想把它输出到文本文件中,但格式会发生变化。如何保存它并保留树的格式呢?

save(m2,file="thisexample.txt", ascii=TRUE)

m2 是存储 J48 树输出的 dataframe


回答:

I. 使用 iris 数据集和 RWekaJ48() 函数的示例。

      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

II. 使用 sink() 函数将其写入文本文件

      sink("result.txt")      print (result)      sink()

III. 打开保存在当前工作目录中的 result.txt 文件。

enter image description here

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注