[Python] Non-integral optimizer parameters in scipy.stats.fit

Discussão em 'Python' iniciado por Stack, Maio 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to fit a distribution to some data using scipy.stats.fit. I specifically need the stats.nbinom distribution to be fit using a non-integer value for parameter n.

    I've made this minimal example of what I'd like to achieve. I can't see what I've done incorrectly.

    This is a modified version of the example here

    from scipy import stats
    from scipy.optimize import differential_evolution
    import numpy as np

    rng = np.random.default_rng()

    def optimizer(fun, bounds, *, integrality):
    return differential_evolution(fun, bounds, strategy='best2bin',
    rng=rng, integrality=[False, False, False])

    data = [0,0,0,1,2,4,11]
    bounds = [(1.5, 1.55), (0, 1)]
    res4 = stats.fit(stats.nbinom, data, bounds, optimizer=optimizer)
    print(res4.params)


    Thanks

    Continue reading...

Compartilhe esta Página