Traceback (most recent call last): File "D:/pycharm/projects/Pythoneeee/projects/d.py", line 65, in <module> coef_mat = np.column_stack((prob_fit.theta_.T, logit_fit.coef_, linear_fit.coef_)) # File "<__array_function__ internals>", line 200, in column_stack File "D:\pycharm\projects\venv\lib\site-packages\numpy\lib\shape_base.py", line 656, in column_stack return _nx.concatenate(arrays, 1) File "<__array_function__ internals>", line 200, in concatenate ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 10 and the array at index 1 has size 1
时间: 2024-03-14 14:47:46 浏览: 223
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误提示是因为`prob_fit.theta_`的维度是`(1, n)`,而`logit_fit.coef_`和`linear_fit.coef_`的维度是`(1,)`和`(1, m)`,所以无法直接进行列合并。可以使用`np.squeeze`方法将`prob_fit.theta_`的维度压缩成`(n,)`,然后再进行列合并。具体代码如下:
```python
prob_theta = np.squeeze(prob_fit.theta_)
coef_mat = np.column_stack((prob_theta, logit_fit.coef_[0], linear_fit.coef_[0]))
```
这里的`np.squeeze`方法可以将维度为1的维度压缩掉,即将`(1, n)`的矩阵转换成`(n,)`的向量。
阅读全文