Search code examples
pythonscipyintrospection

scipy: Which distributions have a "fit" function implemented?


scipy has over a hundred distributions in their stats module, but not all them have a "fit" function implemented. Is there a way to check which distributions have it and which don't?


Solution

  • How about this?

    def distswith(fn='fit'):
        """prints out distributions with '.fit' methods. 
        where any class with a '._pdf' method is considered a distribution
        """
        import scipy.stats
        for fn in dir(scipy.stats):
            fns=eval('dir(scipy.stats.'+fn+')')
            if '_pdf' in fns and 'fit' in fns: 
                print fn
    

    EDIT: looks to me like all 86 do.