拟合曲线而不知道python的功能类型
我正在尝试将平滑曲线适合一组非常嘈杂的数据。通过使用Scipy的“ UnivariateSpline”功能,我几乎设法实现了目标,但是曲线的拟合似乎无法正确适合开始。 第一张图片显示了整个图(红色是拟合的曲线,绿色的数据)。
第一个图
第二张图片在拟合错误的部分中放大。
第二个图,带有拟合错误
是否有人想知道如何使这与绿色数据更加一致?
我尝试将数据的第一部分(从X = 0到Spike,一个指数状的曲线)和第二部分从尖峰的顶部和OUT(负指数函数)分开。但这没用。
最后,重要的是要始终在尖峰之前随着x的增加而增加y的值,而峰值后x的增加则相反。
I'm trying to fit a smooth curve to a set of data that's very noisy. By using the "UnivariateSpline" function from scipy I have almost managed to reach my goal, but the fitting of the curve seems to not be able to fit the beginning correctly.
The first picture shows the whole plot (red is the fitted curve, green the noisy data).
First plot
The second picture is zoomed in on the part that the fitting gets wrong.
Second plot with the fitting error
Does anyone have an idea for how to make this more aligned with the green data?
I have tried splitting up the first part of the data (from x=0 to the spike, an exponential-like curve) and the second part from the top of the spike and out (a negative exponential function). But this didn't work.
In the end, the important thing is to always have increasing values of y with increasing x before the spike, and the opposite with increasing x after the spike.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果数据很嘈杂,并且您不在乎适合噪声,那么插值总是很棘手,因为它专注于拟合所有数据点。不过,一次性分析可能还可以。
您要观察到的问题是平滑因子和数据中急剧过渡设定的权衡。您可以尝试将
s
降低到小于数据点数的值,但是您可能会发现它会开始适合噪声。否则,我建议您尝试安装。请确保使用
activation ='tanh'
,因为这将使函数近似更顺畅。您可能还需要增加alpha
,它可以控制重量衰减,并进一步有助于保持神经网络功能平稳。最后,设置早期_stopping = true
以减少过度拟合噪声的机会。First, if the data is noisy and you don't care to fit the noise, then interpolation is always tricky because of its focus on fitting all the data points. It may be ok for a one-off analysis though.
The issue that you're observing is the trade-off set by the smoothing factor and the sharp transition in your data. You can try to reduce
s
to a value smaller than the number of data points, but you may find that it will start to fit the noise.Otherwise, I'd recommend that you try fitting an MLP model. Be sure to use
activation='tanh'
as that will make the function approximation smoother. You may also want to increasealpha
, which controls the weight decay and further helps to keep the neural net function smooth. Lastly, setearly_stopping=True
to reduce the chances of overfitting to the noise.