Search code examples
pythonscipystatisticsprobabilityprobability-distribution

How to programatically get parameter names and values in scipy


Is there any way to get the parameters of a distribution? I know almost every distribution has "loc" and "scale" but theres differences between them, for example alpha has "a", beta has "a" ,"b".

What i want to do is programatically print(after fiting a distribution) key value pairs of parameter,value.

But i dont want to write a print routine for every possible distribution.


Solution

  • In the end what i did was:

    parameter_names = [p for p in inspect.signature(distribution._pdf).parameters if not p=='x'] + ["loc","scale"]
    parameters = distribution.fit(pd_series)
    distribution_parameters_dictionary =dict(zip(parameter_names,parameters))
    

    Where pd_series is a pandas series of the data being fitted.