全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2146 7
2016-06-24

set.seed(1234)

ind <- sample(2, nrow(iris), replace=TRUE, prob=c(0.7, 0.3))#请问该行中2是什么意思?ind的返回值是多少?

trainData <- iris[ind==1,]为啥是1?

testData <- iris[ind==2,]为啥是2?

iris.rp2=rpart(Species~.,trainData,method="class")

iris.rp3=predict(iris.rp2,testData[,-5],type="class")为啥是-5?

table(testData[,5],iris.rp3)为啥是5?


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-6-25 01:09:54
?sample看看就可以了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-6-25 09:56:53
谢谢,我先看看
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-6-25 10:16:01
Usage(用法)

sample(x, size, replace = FALSE, prob = NULL)
sample.int(n, size = n, replace = FALSE, prob = NULL)
看不懂啊,ind <- sample(2, nrow(iris), replace=TRUE, prob=c(0.7, 0.3))中2代表啥意思呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-6-26 00:58:55
The first argument  "2" means "1" and "2". The second argument is the size of the sample you want create. In this case, it's the number of rows, nrow(iris). The third argument is "replace = T" allowing for replacement; choose "1" and put it back. The fourth argument define the probability for the frequency of "1" and "2"; "1" appears 70% of the time and "2" 30%. The second line of the code use "ind" to split the data into "training" and "test" data using the Learning terminology.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-6-26 09:59:05
ind <- sample(2, nrow(iris), replace=TRUE, prob=c(0.7, 0.3))
>trainData <- iris[ind==1,]
>testData <- iris[ind==2,]
>nrow(trainData)
[1] 109
> nrow(testData)
[1] 41
109:41不等于0.7:0.3,咋回事?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群