Hester12138
2022-01-25 16:14
采纳率: 0%
浏览 34

lowess报错:ValueError: exog must be a vector,如何解决?

想在SHAP的dependence plot上加回归线,使用lowess, 报错:ValueError: exog must be a vector,如何解决?
相关代码:
import statsmodels.api as sm
import math
import numpy as np
import pylab as pl

idx = np.where(cols=="velocity_bin9")
x = X[:,idx]
y_sv = shap_values[:,idx]
lowess = sm.nonparametric.lowess(y_sv, x, frac=.3,it=3, delta=0.0)
_,ax = plt.subplots()
ax.plot(*list(zip(*lowess)), color="red", )

shap.dependence_plot('velocity_bin9', SHAP, Xdata[cols], interaction_index=None,ax=ax, show=False)
###### 运行结果及报错内容 :


ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_31660/1709026442.py in <module>
      7 x = X[:,idx]
      8 y_sv = shap_values[:,idx]
----> 9 lowess = sm.nonparametric.lowess(y_sv, x, frac=.3,it=3, delta=0.0)
     10 _,ax = plt.subplots()
     11 ax.plot(*list(zip(*lowess)), color="red", )

D:\anaconda3\lib\site-packages\statsmodels\nonparametric\smoothers_lowess.py in lowess(endog, exog, frac, it, delta, xvals, is_sorted, missing, return_sorted)
    145     # same length.
    146     if exog.ndim != 1:
--> 147         raise ValueError('exog must be a vector')
    148     if endog.ndim != 1:
    149         raise ValueError('endog must be a vector')

ValueError: exog must be a vector

我想要达到的结果:

img

请指教!!谢谢!!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题