我正在使用分类变量作为预测变量进行普通最小二乘回归(在带有 statsmodels 的 python 中)。分类变量可以有 5 个值。然而,在运行回归之后,输出只包括其中的 4 个。
这是我正在运行的内容:
>>> from statsmodels.formula.api import ols
>>> model = ols("normalized_score ~ C(general_subreddit)", data=df_feature)
>>> results = model.fit()
>>> results.summary()
我可以检查每个分类变量的计数,如下所示:
>>> from collections import Counter
>>> Counter(df_feature["general_subreddit"])
Counter({nan: 20,
'community': 4159,
'ending_addiction': 3819,
'mental_health': 4650,
'other': 6920,
'relationships': 4318})
忽略 NaN,为什么“社区”的分类值没有出现在模型摘要中?
