Python - class 方法是否继承了 class 参数?

Python - Does a class method inherit the class parameters?

在 python 中,我试图了解 StatsModel Linear Mixed Effects Models

型号class是:

class statsmodels.regression.mixed_linear_model.MixedLM(endog, exog, groups, 
                                                        exog_re=None, use_sqrt=True, 
                                                        missing='none', **kwargs)   

有一个 'groups' 参数。我的问题是

class 方法是否继承了 class 参数?

之所以要问,是因为他们写的classmethods they have the method from_formula which does not include the 'groups' parameter. But in the example代码,

model = sm.MixedLM.from_formula("Weight ~ Time", data, re_formula="Time", 
                                groups=data["Pig"])

其中包括 'from_formula' 方法中的 'groups' 参数,因此我的问题是,

class 方法是否继承了 class 参数?

不,根本没有 "class parameters"。有构造函数的参数。

here 所述,args 和 kwargs 被传递给模型(构造函数 - ____init____ 方法)。 然后是模型的对象returns。此方法对您隐藏了一些操作,但如果您知道自己在做什么,则可以传递一些参数,就像将它们传递给构造函数一样。

这些参数是可选的。

args : extra arguments

These are passed to the model

kwargs : extra keyword arguments

These are passed to the model with one exception. The eval_env keyword is passed to patsy. It can be either apatsy.EvalEnvironmentobject or an integer indicating the depth of the namespace to use. For example, the default eval_env=0 uses the calling namespace. If you wish to use a “clean” environment set eval_env=-1.

纯 python 概念接受 class/ 函数中的 *args 和 **kwargs。如果我们不知道传递给任何 class 或函数需要多少参数,我们使用 args 或 kwargs。请仔细阅读此 link args and kwargs. I seen the internal design from_formula,它正在寻找作为 kwargs 的组。