【发布时间】:2020-07-28 08:08:32
【问题描述】:
我有一个适合 SKlearn 的 LinearRegression 模块的回归模型:
为了提取系数,我使用了代码;
coefficients = model.coef_
它产生了以下形状为 (1, 10) 的数组:
[-4.72307152e-05 1.29731143e-04 8.75483702e-05 -6.28749019e-04
1.75096740e-04 -3.30209379e-06 1.35937650e-03 3.89048429e-11
8.48406857e-03 -1.36499030e-05]
现在,我想将数组保存到 pd.Series。我正在采取以下方法:
features = ["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10"]
model_coefs = pd.Series(coefficients, index=features)
而且,系统给了我以下错误:
ValueError: Length of passed values is 1, index implies 10.
我尝试过的:
- 转置基础数组系数,使其长度为 10。
- 重新调整数组的形状,使其形状为 (10,1)。
但似乎没有任何效果。我不确定我哪里出错了。
【问题讨论】:
-
数组中的值之间没有逗号,因此它的形状为 1