您好我正在处理虹膜数据,并且已经能够编译成以下代码(我说编译是因为我编写了简单的代码并将其余部分通过R博客和帮助网站获得,但我很难解释它们。我的目标基本上是了解rpart及其效用:
iris=read.csv("iris.csv")
kmeans.result <- kmeans(iris, 3)
#I received this warning message after the above command and could not understand why:
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In kmeans(iris, 3) : NAs introduced by coercion
table(iris$Species, kmeans.result$cluster)
plot(iris[c("Sepal.length", "Sepal.width")], col = kmeans.result$cluster)
points(kmeans.result$centers[,c("Sepal.length", "Sepal.width")], col = 1:3,
pch=8, cex=2)
#I installed rpart and got the second command from a blog (did not write that myself) that I just modified for the data name and got a plot with out labels:
library(rpart)
iris.rp <-rpart(Species ~ . ,
data = iris,
method = "class",
parms = list(split = "information"),
maxsurrogate = 0,
cp = 0,
minsplit = 5,
minbucket = 2,
)
plot(iris.rp)
任何帮助理解/改进它都会非常有帮助!