文档

数据样本

从数据中随机采样,有或没有替换

句法

y= datasampe(data,k)
y= datasampe(data,k,dim)
[Y,IDX] = DataSample(数据,K,...)
[y,...] =数据样本(s,data,k,...)
[[y,...] =数据样本(data,k,Name,Value)
[[y,...] =数据样本(data,k,dim,Name,Value)

Description

y= datasampe(data,,,,k返回kobservations sampled uniformly at random, with replacement, from the data indata

y= datasampe(data,,,,k,,,,暗淡返回沿维度采集的样本暗淡ofdata

[[y,,,,IDX] = datasample(data,,,,k,,,,。。。)返回索引值向量表示数据样本data

[[y,...] =数据样本(s,,,,data,,,,k,,,,。。。)使用随机数流s生成随机数。

[[y,...] =数据样本(data,,,,k,,,,名称,价值or[[y,...] =数据样本(data,,,,k,,,,暗淡,,,,名称,价值samples with additional options specified by one or more名称,价值pair arguments.

输入参数

data

Vector, matrix,n- 维数阵列,table, or dataset array representing the data from which to sample. By default,数据样本regards the rows of adatamatrix, or the first nonsingleton dimension of adata数组,作为数据元素。改变这种行为暗淡argument.

k

正整数,样品数量。

暗淡

整数指定采样的尺寸。例如,如果data是a matrix and暗淡2,,,,ycontains a selection of columns indata。如果data是表或数据集数组,暗淡2,,,,y包含一系列变量data。利用暗淡为了确保沿特定维度采样data是矢量,matrix orn- 维数阵列。

默认:1

s

随机数流。创造s使用rngorRandstream

默认:全局随机数流

姓名-Value Pair Arguments

指定可选的逗号分隔对名称,价值arguments.姓名是参数名称和Value是the corresponding value.姓名must appear inside single quotes ('')。您可以按任何顺序指定几个名称和值对参数姓名1,,,,Value1,...,NameN,ValueN

'Replace'

选择替换的样品代替true,或不替换代替错误的。如果代替错误的,,,,k不得大于data

默认:true

“重量”

与数据元素相同的元素数量的向量data,,,,and with nonnegative elements. Sample with probability proportional to the elements of权重

默认:ones(datasize,1), 在哪里DataSize是the number of data elements indata

输出参数

y

  • 如果data是矢量,y是一个载体k从中选择的元素data

  • 如果data是矩阵,y是一个包含的矩阵k选择的行data。或者如果暗淡=2,,,,y是一个包含的矩阵kcolumns selected fromdata

  • 如果data是ann- 维数阵列,数据样本samples along its first non-singleton dimension. Or, if you give a暗淡名称对,数据样本samples along the dimension暗淡

When the sample is taken with replacement (default),y可以包含重复的观察结果data。设置代替name-value pair to错误的无需替换品采样。

IDX

指示哪些元素的索引向量数据样本从中选择datato createy。例如:

  • 如果data是矢量,y=data(idx)

  • 如果data是矩阵,y=data(idx,:)

Examples

Draw five unique values from the integers1:10

y= datasampe(1:10,,,,5,'Replace',false) y = 6 3 7 8 5

Generate a random sequence of the charactersACGT,,,,with replacement, according to specified probabilities.

seq = datasample('ACGT',48,'Weights',[0.15 0.35 0.35 0.15]) seq = CTTCGACTGTGAGTGGGCGCGACAAGGCTACCGGCCCGGGCGGCACTC

Select a random subset of columns from a data matrix.

x = randn(10,1000);Y = datasample(X,5,2,'Replace',false) Y = 0.7007 0.3382 2.1298 -0.1891 0.5026 0.6520 -0.6693 -0.1961 -0.9915 1.9107 0.1785 0.6640 2.3247 -1.1735 -1.0020 1.6760 2.6102 -0.8902 -0.7735 1.8676 -0.3251 -0.6415-0.2572 -0.1629 -1.0523 0.1011 0.9323 -1.3088 -0.4477 0.8036 -0.5767 -0.5778 -0.8556 0.8672 -0.0727 -0.0615 -0.9084 0.9020 -0.4185 -1.9520 0.7256 -1.1228 0.7558 1.2691 2.4997 -1.2273 0.5754 -0.8755 -0.8224 -1.2066

Resample observations from a dataset array to create a bootstrap replicate dataset.

负载医院y =数据样本(医院,大小(医院,1));

使用第二个输出从两个数据向量进行“并行”采样。

x1 = randn(100,1);x2 = randn(100,1);[Y1,IDX] = DataSample(x1,10);y2 = x2(idx);

Tips

  • 要从范围替换的随机整数采样,请使用兰迪

  • 要在不替换的情况下采样随机整数,请使用兰德珀or数据样本

  • 从数据中随机采样,或者没有替换,请使用数据样本

Algorithms

数据样本uses兰德珀,,,,兰德, 或者兰迪生成随机值。所以,数据样本changes the state of the MATLAB®全局随机数生成器。使用随机数生成器使用rng

用于在不替换的情况下选择加权样品,数据样本使用Wong和Easton的算法[[1]

备择方案

You can use兰迪or兰德珀to generate indices for random sampling with or without replacement, respectively. However,数据样本can be more convenient because it samples directly from your data.数据样本also allows weighted sampling.

References

[[1] Wong, C. K. and M. C. Easton.An Efficient Method for Weighted Sampling Without Replacement.SIAM计算杂志9(1),第111–113页,1980年。

扩展功能

也可以看看

||||

话题

    Introduced in R2011b

    Was this topic helpful?