# The programming behind the Stratified sampling in KNIME

**URL:** <https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177>\
**Category:** KNIME Analytics Platform\
**Created:** [October 25, 2013, 11:45am UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177 "2013-10-25T11:45:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Error404](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@Error404](https://forum.knime.com/u/Error404)\
**Post date:** [October 25, 2013, 11:45am UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177/1 "2013-10-25T11:45:12Z")

</div>

Hi all,

&nbsp;

I am working with a dataset from which I need to sample every now and then. I normally use the node "row sampling" and choose the option of "stratified sampling" to get my samples. I have been recently reading and found out that there are 2 different approaches that gives a sample under the term "stratified sampling" ([from Wikipedia](http://en.wikipedia.org/wiki/Stratified_sampling)).

&nbsp;

One of them depends on the "sampling fraction" where the size of samples (assume it is sampling from 2 groups,&nbsp;A&nbsp;and B)&nbsp;have to reflect the original distribution, While the other one depends on the standard devation, making stratums that are similar (or close) in standard deviation to the original data. My question here is which one of these 2 approaches does the "row sampling" node use in the "stratified sampling" option?

&nbsp;

Many thanks,

Error404

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [October 25, 2013, 12:40pm UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177/2 "2013-10-25T12:40:07Z")

</div>

The first one, the proportions of the occurrences of the different values in the column are retained.

---

<div class="post-metadata">

**Author:** ![Error404](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@Error404](https://forum.knime.com/u/Error404)\
**Post date:** [October 25, 2013, 12:48pm UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177/3 "2013-10-25T12:48:43Z")

</div>

Thanks for your reply. I now understand how this works, but what if the column I set as the "nominal column" contain only 1 nominal category?

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [October 26, 2013, 10:29am UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177/4 "2013-10-26T10:29:00Z")

</div>

Then it's a purely random sampling.

---

<div class="post-metadata">

**Author:** ![Error404](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@Error404](https://forum.knime.com/u/Error404)\
**Post date:** [October 27, 2013, 7:36pm UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177/5 "2013-10-27T19:36:56Z")

</div>

Thanks for your replies Thor. Just to make sure I get this correctly (as this step is important for me), if I had a sample that belongs to 2 groups. Group A represents 80% and Group B represents 20% of the data and I perform this "stratified sampling" the sample will have the same property of consisting of 80% items from A and 20% items from B and all these items will&nbsp;be RANDOMLY drawn from the original A and B groups. Is that correct?

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [October 28, 2013, 9:10am UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177/6 "2013-10-28T09:10:16Z")

</div>

Correct.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 23, 2023, 8:18pm UTC](https://forum.knime.com/t/the-programming-behind-the-stratified-sampling-in-knime/3177/7 "2023-06-23T20:18:52Z")

</div>


