Traceback (most recent call last): File "C:\Users\Administrator\Desktop\transformer_final\Transformer_V2_radicla_single.py", line 157, in <module> main() File "C:\Users\Administrator\Desktop\transformer_final\Transformer_V2_radicla_single.py", line 148, in main pred_smooth = savgol_filter(pred, window_size, poly_order) File "D:\anaconda2\lib\site-packages\scipy\signal\_savitzky_golay.py", line 345, in savgol_filter raise ValueError("If mode is 'interp', window_length must be less " ValueError: If mode is 'interp', window_length must be less than or equal to the size of x.什么原因?代码是这样的x = range(1, 161) pred = np.array(pred) pred = pred.reshape(160, 1) window_size = 3 poly_order = 2 pred_smooth = savgol_filter(pred, window_size, poly_order) plt.figure() plt.plot(x, pred, c='green', label='pred') plt.plot(x, pred_smooth, c='yellow', label='pred_smooth') plt.plot(x, aaa[:, 0], c='black', label='xtrain') plt.show()
时间: 2024-04-18 09:24:15 浏览: 170
解决pandas read_csv 读取中文列标题文件报错的问题
根据你提供的代码和错误信息,问题出现在ValueError: If mode is 'interp', window_length must be less than or equal to the size of x`这一行。这个错误是由于使用`savgol_filter`函数时,`window_length`参数的值大于了输入数组`x`的长度引起的。
根据你提供的代码,我们可以看到`x`的长度为160,而`window_length`参数的值为3。因此,导致了这个错误。
要解决这个问题,你可以将`window_length`参数的值设置得小于或等于输入数组`x`的长度,或者检查一下你的数据是否符合预期。
阅读全文