当我尝试从Scipy packsaage导入savgol_filter时,我试图平滑曲线以便于读取图形中的尖峰,但它看起来并不起作用。
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import savgol_filter
x = np.linspace(0,2*np.pi,100)
y = np.sin(x) + np.random.random(100) * 0.2
yhat = savitzky_golay(y, 51, 3) # window size 51, polynomial order 3
plt.plot(x,y)
plt.plot(x,yhat, color='red')
plt.show()
from scipy.signal import savgol_filter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name savgol_filter
我正在考虑使用线性回归来做到这一点,但它似乎并没有起作用。