r - 我如何制作这样的回归树?

标签 r tree regression rpart

我想做一个像图中那样的回归树。这棵树是在 Cubist 中完成的,但我没有那个程序。我确实使用 R 和 Python。它似乎与 R 包 rpart 或 tree 的不同之处在于端节点是线性公式而不仅仅是平均值。有什么方法可以使用 R 或其他一些免费软件来做到这一点?

图中NDVI、B1、B2等为变量。图片来自this website .

regression tree

最佳答案

Cubist是 RuleQuest 在 http://rulequest.com/cubist-info.html 发布的 Cubist GPL C 代码的 R 端口.

使用 help('cubist') 中的示例和原始 package announcement

library(Cubist)
library(mlbench)
data(BostonHousing)

## 1 committee, so just an M5 fit:
mod1 <- cubist(x = BostonHousing[, -14], y = BostonHousing$medv)
summary(mod1)

# Call:
#   cubist.default(x = BostonHousing[, -14], y = BostonHousing$medv)
# 
# 
# Cubist [Release 2.07 GPL Edition]  Thu Jul 04 11:56:33 2013
# ---------------------------------
#   
#   Target attribute `outcome'
# 
# Read 506 cases (14 attributes) from undefined.data
# 
# Model:
# 
# Rule 1: [101 cases, mean 13.84, range 5 to 27.5, est err 1.98]
# 
# if
# nox > 0.668
# then
# outcome = -1.11 + 2.93 dis + 21.4 nox - 0.33 lstat + 0.008 b
# - 0.13 ptratio - 0.02 crim - 0.003 age + 0.1 rm
# 
# Rule 2: [203 cases, mean 19.42, range 7 to 31, est err 2.10]
# 
# if
# nox <= 0.668
# lstat > 9.59
# then
# outcome = 23.57 + 3.1 rm - 0.81 dis - 0.71 ptratio - 0.048 age
# - 0.15 lstat + 0.01 b - 0.0041 tax - 5.2 nox + 0.05 crim
# + 0.02 rad
# 
# Rule 3: [43 cases, mean 24.00, range 11.9 to 50, est err 2.56]
# 
# if
# rm <= 6.226
# lstat <= 9.59
# then
# outcome = 1.18 + 3.83 crim + 4.3 rm - 0.06 age - 0.11 lstat - 0.003 tax
# - 0.09 dis - 0.08 ptratio
# 
# Rule 4: [163 cases, mean 31.46, range 16.5 to 50, est err 2.78]
# 
# if
# rm > 6.226
# lstat <= 9.59
# then
# outcome = -4.71 + 2.22 crim + 9.2 rm - 0.83 lstat - 0.0182 tax
# - 0.72 ptratio - 0.71 dis - 0.04 age + 0.03 rad - 1.7 nox
# + 0.008 zn
# 
# 
# Evaluation on training data (506 cases):
# 
# Average  |error|               2.10
# Relative |error|               0.32
# Correlation coefficient        0.94
# 
# 
# Attribute usage:
# Conds  Model
# 
# 80%   100%    lstat
# 60%    92%    nox
# 40%   100%    rm
# 100%    crim
# 100%    age
# 100%    dis
# 100%    ptratio
# 80%    tax
# 72%    rad
# 60%    b
# 32%    zn
# 
# 
# Time: 0.0 secs

关于r - 我如何制作这样的回归树?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17460595/

相关文章:

unit-testing - 机器学习算法的单元测试实现或包装

java - 二叉节点树,错误的父子

tree - 平衡树的定义

python - 如何将变量文件名传递给 python ete?

python - 如何避免回归模型中的浮点值

python - 了解 TensorFlow LSTM 输入形状

r - 将strptime函数应用于data.table的每个成员

r - 在 R 中定义自定义调色板

r - 如何将日期和预测添加到 data.frame?

r - 计算 `dplyr` 管道中的累积概率(Kaplan-Meier 生存函数)