0

Looking at some of the source code from the sklearn library:

https://github.com/scikit-learn/scikit-learn/blob/277b058713f64f55e787aac55fe0e1bbbd47576f/sklearn/utils/init.py#L186

part of the code, removing the comments:

def check_random_state(seed):
    if seed is None or seed is np.random:
        return np.random.mtrand._rand
    if isinstance(seed, (numbers.Integral, np.integer)):
        return np.random.RandomState(seed)
    if isinstance(seed, np.random.RandomState):
        return seed
    raise ValueError('%r cannot be used to seed a numpy.random.RandomState' ' instace' % seed)

def resample(*arrays, **options):
    random_state = check_random_state(options.pop('random_state', None))
    replace = options.pop('replace', True)
    # lots more code below ...

In particular: replace = options.pop('replace', True) and random_state = check_random_state(options.pop('random_state', None)) how is the options.pop('object_that_is_being_created', some_value) used? What is it's purpose? What does it do?

I know that options will be a dictionary and that arrays will be a tuple, but im not sure what the code actually, since it seems it just returns the second argument ?

UberStuper
  • 356
  • 3
  • 17
  • It returns the value of the `replace` argument to the function, or `True` if the argument wasn't supplied. – Barmar Sep 17 '16 at 00:04
  • @Barmar so in the function call `resample(*arrays, **options)` one of the keys for the options dictionary will be `replace`, and it's value will be given to the `replace` variable that is being created? – UberStuper Sep 17 '16 at 00:09
  • That's correct. If you call `resample(..., replace=False, ...)` then it will use that value instead of the default. – Barmar Sep 17 '16 at 00:10

0 Answers0