我正在尝试在R-cran中使用树包。我正在加载我的 csv 文件,如下所示:
data <- read.csv("C:/data2.csv", header = FALSE, sep = ";",dec = ".")
文件中的最后一列代表 Class正确吗?
我的问题是该类应该在文件的第一列还是 las 列中表示,谢谢。
V1 V2 V3 V4 V5 CLASS
'X0000002' NULL 0 NULL 'BETA' 1
'Y0034195' NULL 2 NULL 'INTERNAL' 1
'X0000001' NULL 0 NULL 'BETA' 2
'X0000002' NULL 0 NULL 'BETA' 2
'X0000002' NULL 0 NULL 'BETA' 2
'Y0034195' NULL 0 NULL 'INTERNAL' 2
更正 好的,我有 24 个描述符 V1...V24。V24 是类。我在 R Cran 中使用了 Rpart 库
library(rpart)
data <- read.csv("C:/data2.csv", header = FALSE, sep = ";",dec = ".")
d1-> data[,1:24]
fit <- rpart(v24~ v1+v2+v3+v4+v5+v6+v7+v8+v9+v10+v11+v12+v13+v14+v15+v16+v17+v18+v19+V20+v21+v22+v23,data=d1)
我收到以下错误找不到对象'V24'
示例:解决方案
# Regression Tree Example
library(rpart)
data <- read.csv("C:/data2.csv", header = T,sep=";")
fit = rpart(linkId ~ .,method = "anova",data = data)
printcp(fit) # display the results
plotcp(fit) # visualize cross-validation results
summary(fit) # detailed summary of splits
# create additional plots
par(mfrow=c(1,2)) # two plots on one page
rsq.rpart(fit) # visualize cross-validation results
# plot tree
plot(fit, uniform=FALSE,
main="Regression Tree for Mileage ",compress = TRUE )
text(fit, use.n=TRUE, all=TRUE, cex=.8)
# create attractive postcript plot of tree
post(fit, file = "c:/tree2.ps",
title = "Arbre de Regression ")