statsmodels.gam.smooth_basis.BSplines

class statsmodels.gam.smooth_basis.BSplines(x, df, degree, include_intercept=False, constraints=None, variable_names=None, knot_kwds=None)[source]

使用B样条的加性平滑分量

这创建并保存了多个分量的B样条基函数。

Parameters:
xarray_like, 1-D or 2-D

平滑项的潜在解释变量。 如果是二维的,那么观测值应在行中,解释变量应在列中。

df{int, array_like[int]}

基函数或自由度的数量;应与x的列数相等;如果x只有一列或是一维的,则可以是一个整数。

degree{int, array_like[int]}

样条的次数;与df相同的长度和类型规则适用

include_interceptbool

如果为False,则将基函数进行变换,使其不包含常数项。这避免了如果模型中包含常数或多个成分时出现完全共线性的情况。

constraints{None, str, array}

约束用于将基函数转换为满足这些约束条件。 constraints = ‘center’ 应用线性变换以去除常数项并将基函数居中。

variable_names{list[str], None}

用于创建基函数列和参数名称的底层解释变量 x 的名称。如果 x 是一个 pandas 对象,那么名称将从其中获取。

knot_kwdsNone or list of dict

结点选择的选项。 默认情况下,结点的选择方式与patsy相同,但是结点的数量与保留或删除常数项无关。 内部结点的选择基于数据的百分位数,并且在patsy和mgcv中是相同的。边界点位于数据范围的极限处。 可用的选项与get_knots_bsplines一起使用的是

  • 结点 : 无或数组 内部结点

  • spacing : ‘分位数’ 或 ‘等距’

  • lower_bound : None 或 float 下边界节点位置,所有边界节点都在同一点

  • upper_bound : 无或浮点数 上边界节点的位置,所有边界节点都在同一点

  • all_knots : 无或数组 如果提供了所有节点,那么这些节点将被视为给定的,并且所有其他选项将被忽略。

Attributes:
smootherslist of univariate smooth component instances
basisdesign matrix, array of spline bases columns for all components
penalty_matriceslist of penalty matrices, one for each smooth term
dim_basisnumber of columns in the basis
k_variablesnumber of smooth components
col_namescreated names for the basis columns
There are additional attributes about the specification of the splines
and some attributes mainly for internal use.

注释

在样条基函数中的一个常数可以通过两种不同的方式去除。 第一种方法是通过去掉一个基列并归一化剩余的列。这是通过默认的 include_intercept=False, constraints=None 实现的。第二种选择是使用中心化变换,这是一种对所有基函数的线性变换。由于这种变换,B样条基函数不再具有局部有界支持。这是通过 constraints='center' 实现的。在这种情况下, include_intercept 将自动设置为 True,以避免去掉额外的列。

方法

transform(x_new)

为新观测值创建样条基


Last update: Oct 16, 2024