Turn seed into an np.random.RandomState instance. Parameters ---------- seed : None, int or instance of RandomState If seed is None, return the RandomState singleton used by np.random. If seed is an int, return a new RandomState instance seeded with seed. If seed
(seed)
| 1450 | |
| 1451 | |
| 1452 | def check_random_state(seed): |
| 1453 | """Turn seed into an np.random.RandomState instance. |
| 1454 | |
| 1455 | Parameters |
| 1456 | ---------- |
| 1457 | seed : None, int or instance of RandomState |
| 1458 | If seed is None, return the RandomState singleton used by np.random. |
| 1459 | If seed is an int, return a new RandomState instance seeded with seed. |
| 1460 | If seed is already a RandomState instance, return it. |
| 1461 | Otherwise raise ValueError. |
| 1462 | |
| 1463 | Returns |
| 1464 | ------- |
| 1465 | :class:`numpy:numpy.random.RandomState` |
| 1466 | The random state object based on `seed` parameter. |
| 1467 | |
| 1468 | Examples |
| 1469 | -------- |
| 1470 | >>> from sklearn.utils.validation import check_random_state |
| 1471 | >>> check_random_state(42) |
| 1472 | RandomState(MT19937) at 0x... |
| 1473 | """ |
| 1474 | if seed is None or seed is np.random: |
| 1475 | return np.random.mtrand._rand |
| 1476 | if isinstance(seed, numbers.Integral): |
| 1477 | return np.random.RandomState(seed) |
| 1478 | if isinstance(seed, np.random.RandomState): |
| 1479 | return seed |
| 1480 | raise ValueError( |
| 1481 | f"{seed!r} cannot be used to seed a numpy.random.RandomState instance" |
| 1482 | ) |
| 1483 | |
| 1484 | |
| 1485 | def has_fit_parameter(estimator, parameter): |
no outgoing calls
searching dependent graphs…