2

I would like to receive the distribution name and parameters from the user as input and generate a probability distribution from which I can choose a random number proportional to their probability. I checked https://docs.scipy.org/doc/scipy/reference/stats.html. At most, 5 parameters are required to generate all the probability distributions defined in scipy library.

dist_params = {
        'distribution': 'expon',
        'param1': 0,
        'param2': 1,
        'param3': None,
        'param4': None,
        'param5': None
}

Given the above input, I can create an exponential distribution and choose a number from that distribution:

import scipy.stats as st
import numpy as np
import random

population = np.linspace(start=1, stop=100, num=20)
dist = getattr(st, dist_params['distribution'])
population_probabilities = dist.pdf(population, dist_params['param1'], dist_params['param2'], ...)
random.choice(population, population_probabilities) 

How can I generalize this for any type of distribution?

John
  • 99
  • 5

0 Answers0