Accord.NET Framework

## ClassesSeparateT Method (T, Int32, Int32) |

Divides values into groups given a vector
containing the group labels for every value.

Syntax

Request Example
View Source#### Parameters

#### Type Parameters

#### Return Value

Type: T

The original values divided into groups.#### Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

- values
- Type: T

The values to be separated into groups. - labels
- Type: SystemInt32

A vector containing the class label associated with each of the values. The labels must begin on 0 and its maximum value should be the number of groups - 1. - groups
- Type: SystemInt32

The number of groups.

- T
- The type of the values.

The original values divided into groups.

Examples

// The Classes.Random method can be used to generate random class // assignments. For example, let's say we would like to generate // 100 binary assignments where the probability of having a positive // class assignment is of 80%: int[] y1 = Classes.Random(samples: 100, proportion: 0.8); // If we compute the histogram of y, the result will be: int[] hist1 = y1.Histogram(); // new int[] { 80, 20 } // Let's say we would like to generate 100 assignments // where samples can belong to 1 of 3 different classes: int[] y2 = Classes.Random(samples: 100, classes: 3); // The histogram of y will be: int[] hist2 = y2.Histogram(); // new int[] { 34, 33, 33 } // Let's say we would like to generate the sample sample as above, // but we would like to control how many samples should fall into // each of the 3 categories: int[] y3 = Classes.Random(samples: 100, proportion: new[] { 0.2, 0.5, 0.3}); // The histogram of y will be: int[] hist3 = y3.Histogram(); // new int[] { 20, 50, 30 } // The Random method can also generate balanced assignments according // to some pre-existing division. Let's say we have 100 samples that // have been already divided into 5 groups (i.e. the last result of y). // Now, we would like to separate those into two different groups such // that the proportion between the different classes in y is kept balanced // within those sub-groups: int[] y4 = Classes.Random(y3, categories: 2); // The histogram of y4 will be: int[] hist4 = y4.Histogram(); // new int[] { 50, 50 } // However, we can use those assignments to separate // the y3 labels into two 50-50 groups as we intended: int[][] r = Classes.Separate(y3, y4); // And as we can see, proportions are the same in both groups: int[] rhist1 = r[0].Histogram(); // new int[] { 10, 25, 15 } int[] rhist2 = r[1].Histogram(); // new int[] { 10, 25, 15 }

See Also