statsmodels.discrete.discrete_model.NegativeBinomialP.fit

NegativeBinomialP.fit(start_params=None, method='bfgs', maxiter=35, full_output=1, disp=1, callback=None, use_transparams=False, cov_type='nonrobust', cov_kwds=None, use_t=None, optim_kwds_prelim=None, **kwargs)[source]
use_transparamsbool

此参数启用内部转换以强制非负性。启用为True。默认值为False。 use_transparams=True 强制执行无欠分散(alpha > 0)约束。如果 use_transparams=True 且 method=“newton” 或 “ncg”,则转换将被忽略。

使用最大似然法拟合模型。

文档字符串的其余部分来自 statsmodels.base.model.LikelihoodModel.fit

基于似然模型的拟合方法

Parameters:
start_paramsarray_like, optional

对数似然最大化解决方案的初始猜测。 默认是一个零数组。

methodstr, optional

方法决定了从scipy.optimize中使用哪个求解器,并且可以从以下字符串中选择:

  • ‘newton’ 表示牛顿-拉夫森法,‘nm’ 表示内尔德-米德法

  • ‘bfgs’ 用于 Broyden-Fletcher-Goldfarb-Shanno (BFGS)

  • ‘lbfgs’ 用于带可选边界约束的有限内存BFGS

  • ‘powell’ 表示修正的鲍威尔法

  • ‘cg’ 表示共轭梯度

  • ‘ncg’ 表示牛顿共轭梯度法

  • ‘basinhopping’ 用于全局 basin-hopping 求解器

  • ‘minimize’ 用于通用的 scipy minimize 包装器(默认使用 BFGS)

fit中的显式参数会传递给求解器,除了basin-hopping求解器。每个求解器都有几个可选参数,这些参数在不同的求解器之间并不相同。请参阅下面的注释部分(或scipy.optimize)以获取可用参数的列表以及basin-hopping求解器支持的显式参数列表。

maxiterint, optional

要执行的最大迭代次数。

full_outputbool, optional

设置为 True 以在 Results 对象的 mle_retvals 属性中获取所有可用输出。输出内容取决于求解器。有关更多信息,请参阅 LikelihoodModelResults 注释部分。

dispbool, optional

设置为 True 以打印收敛消息。

fargstuple, optional

传递给似然函数的额外参数,即, loglike(x,*args)

callbackcallable callback(xk), optional

在每次迭代后调用,作为回调函数(xk),其中xk是当前的参数向量。

retallbool, optional

设置为 True 以返回每次迭代的解决方案列表。 可在 Results 对象的 mle_retvals 属性中获取。

skip_hessianbool, optional

如果为 False(默认值),则在优化后计算负逆 Hessian。如果为 True,则不会计算 Hessian。但是,在使用 Hessian 进行优化的方法中(目前仅在使用 “newton” 时),它将可用。

kwargskeywords

所有关键字参数都会传递给选定的求解器,但有一个例外。以下关键字控制拟合后的操作:

warn_convergence : bool, optional
    If True, checks the model for the converged flag. If the
    converged flag is False, a ConvergenceWarning is issued.

注释

‘basinhopping’ 求解器忽略 maxiterretallfull_output 显式参数。

求解器的可选参数(参见返回的 Results.mle_settings):

'newton'
    tol : float
        Relative error in params acceptable for convergence.
'nm' -- Nelder Mead
    xtol : float
        Relative error in params acceptable for convergence
    ftol : float
        Relative error in loglike(params) acceptable for
        convergence
    maxfun : int
        Maximum number of function evaluations to make.
'bfgs'
    gtol : float
        Stop when norm of gradient is less than gtol.
    norm : float
        Order of norm (np.inf is max, -np.inf is min)
    epsilon
        If fprime is approximated, use this value for the step
        size. Only relevant if LikelihoodModel.score is None.
'lbfgs'
    m : int
        This many terms are used for the Hessian approximation.
    factr : float
        A stop condition that is a variant of relative error.
    pgtol : float
        A stop condition that uses the projected gradient.
    epsilon
        If fprime is approximated, use this value for the step
        size. Only relevant if LikelihoodModel.score is None.
    maxfun : int
        Maximum number of function evaluations to make.
    bounds : sequence
        (min, max) pairs for each element in x,
        defining the bounds on that parameter.
        Use None for one of min or max when there is no bound
        in that direction.
'cg'
    gtol : float
        Stop when norm of gradient is less than gtol.
    norm : float
        Order of norm (np.inf is max, -np.inf is min)
    epsilon : float
        If fprime is approximated, use this value for the step
        size. Can be scalar or vector.  Only relevant if
        Likelihoodmodel.score is None.
'ncg'
    fhess_p : callable f'(x,*args)
        Function which computes the Hessian of f times an arbitrary
        vector, p.  Should only be supplied if
        LikelihoodModel.hessian is None.
    avextol : float
        Stop when the average relative error in the minimizer
        falls below this amount.
    epsilon : float or ndarray
        If fhess is approximated, use this value for the step size.
        Only relevant if Likelihoodmodel.hessian is None.
'powell'
    xtol : float
        Line-search error tolerance
    ftol : float
        Relative error in loglike(params) for acceptable for
        convergence.
    maxfun : int
        Maximum number of function evaluations to make.
    start_direc : ndarray
        Initial direction set.
'basinhopping'
    niter : int
        The number of basin hopping iterations.
    niter_success : int
        Stop the run if the global minimum candidate remains the
        same for this number of iterations.
    T : float
        The "temperature" parameter for the accept or reject
        criterion. Higher "temperatures" mean that larger jumps
        in function value will be accepted. For best results
        `T` should be comparable to the separation (in function
        value) between local minima.
    stepsize : float
        Initial step size for use in the random displacement.
    interval : int
        The interval for how often to update the `stepsize`.
    minimizer : dict
        Extra keyword arguments to be passed to the minimizer
        `scipy.optimize.minimize()`, for example 'method' - the
        minimization method (e.g. 'L-BFGS-B'), or 'tol' - the
        tolerance for termination. Other arguments are mapped from
        explicit argument of `fit`:
          - `args` <- `fargs`
          - `jac` <- `score`
          - `hess` <- `hess`
'minimize'
    min_method : str, optional
        Name of minimization method to use.
        Any method specific arguments can be passed directly.
        For a list of methods and their arguments, see
        documentation of `scipy.optimize.minimize`.
        If no method is specified, then BFGS is used.

Last update: Oct 16, 2024