* Returns specified number of random rows in a Series * @param num The number of rows to return * @param options.seed An integer specifying the random seed that will be used to create the distribution. * @example * ``` * const df = new Series([1, 2, 3, 4]) * const df2 =
(num = 5, options?: { seed?: number })
| 210 | * ``` |
| 211 | */ |
| 212 | async sample(num = 5, options?: { seed?: number }): Promise<Series> { |
| 213 | const { seed } = { seed: 1, ...options } |
| 214 | |
| 215 | if (num > this.shape[0]) { |
| 216 | throw new Error("Sample size n cannot be bigger than size of dataset"); |
| 217 | } |
| 218 | if (num < -1 || num == 0) { |
| 219 | throw new Error("Sample size cannot be less than -1 or be equal to 0"); |
| 220 | } |
| 221 | num = num === -1 ? this.shape[0] : num; |
| 222 | |
| 223 | const shuffledIndex = await tensorflow.data.array(this.index).shuffle(num, `${seed}`).take(num).toArray(); |
| 224 | const sf = this.iloc(shuffledIndex); |
| 225 | return sf; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Return Addition of series and other, element-wise (binary operator add). |