楼主: jiajiaqiqigugu
2209 7

[问答] 决策树 [推广有奖]

  • 0关注
  • 2粉丝

硕士生

68%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1283 点
帖子
113
精华
0
在线时间
92 小时
注册时间
2016-6-10
最后登录
2017-4-9

楼主
jiajiaqiqigugu 发表于 2016-6-24 20:53:53 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

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?


二维码

扫码加我 拉你入群

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

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

关键词:决策树 seed IND see Set

沙发
bbslover 在职认证  发表于 2016-6-25 01:09:54
?sample看看就可以了

藤椅
jiajiaqiqigugu 发表于 2016-6-25 09:56:53
谢谢,我先看看

板凳
jiajiaqiqigugu 发表于 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代表啥意思呢?

报纸
waterhorse 发表于 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.

地板
jiajiaqiqigugu 发表于 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,咋回事?

7
1101262429 发表于 2018-12-28 16:58:26
jiajiaqiqigugu 发表于 2016-6-25 10:16
Usage(用法)

sample(x, size, replace = FALSE, prob = NULL)
sample(x, size, replace = FALSE, prob = NULL)
参数的含义如下:
x:为向量,表示抽样的总体,或者是一个正整数,表示样本总体为1~n;
size:为样本容量,即要抽取的样本个数,是一个非负整数;
replace:表示是否为有放回的抽样,是一个逻辑值,默认为FALSE,即默认为无放回抽样;
prob:为权重向量,即x中元素被抽取到的概率,是一个取值0~1的向量,其长度应该与x的长度相同。
2 表示样本抽取2份

8
啊啊啊啊啊吖 发表于 2018-12-28 17:41:36
6666,学习了给各位大佬递茶

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-18 15:54