statsmodels.multivariate.factor.FactorResults.get_loadings_frame

FactorResults.get_loadings_frame(style='display', sort_=True, threshold=0.3, highlight_max=True, color_max='yellow', decimals=None)[source]

获取载荷矩阵为 DataFrame 或 pandas Styler

Parameters:
style‘display’ (default), ‘raw’ or ‘strings’

用于显示的样式

  • ‘raw’ returns just a DataFrame of the loadings matrix, no options are

    应用

  • ‘display’ 添加排序和样式,由其他关键字定义

  • ‘strings’ returns a DataFrame with string elements with optional sorting

    并抑制小的加载系数。

sort_bool

如果为真,则按每个因素的贡献对DataFrame的行进行排序。适用于样式为‘display’或‘strings’的情况

thresholdfloat

如果阈值大于零,则加载系数将被着色为白色(如果样式为‘display’)或替换为空字符串(如果样式为‘strings’)。

highlight_maxbool

这将为每行中最大的系数添加背景颜色。

color_maxhtml color

默认值为‘yellow’。行最大值的背景颜色

decimalsNone or int

如果为None,则应用pandas默认精度。否则,值将四舍五入到指定的位数。如果样式为‘display’,则底层数据框不会更改。如果样式为‘strings’,则在转换为字符串之前对值进行四舍五入。

Returns:
loadingsDataFrame or pandas Styler instance

返回的是一个 pandas Styler 实例,如果 style 是 ‘display’ 并且至少应用了 highlight_max、threshold 或 decimals 中的一个。否则,返回的 loadings 是一个 DataFrame。

示例

>>> mod = Factor(df, 3, smc=True)
>>> res = mod.fit()
>>> res.get_loadings_frame(style='display', decimals=3, threshold=0.2)

要获取排序后的DataFrame,所有样式选项都需要关闭:

>>> df_sorted = res.get_loadings_frame(style='display',
...             highlight_max=False, decimals=None, threshold=0)

除了高亮显示外,其他选项适用于纯文本或Latex使用:

>>> lds = res_u.get_loadings_frame(style='strings', decimals=3,
...                                threshold=0.3)
>>> print(lds.to_latex())

Last update: Oct 16, 2024