Python内核平滑

Python内核平滑,python,r,scikit-learn,smoothing,kernel-density,Python,R,Scikit Learn,Smoothing,Kernel Density,我有一些R代码,我正试图在Python中复制它们。在R文件中,我有一个数据帧,我用 smoothedTime <- ksmooth(1:length(df$time), df$time, bandwidth=100, x.points=(1:length(df$time)))$y 结果仍然不同。我想知道为什么我得不到同样的答案,我能做些什么才能得到同样的答案 有关守则如下: Python代码: import skfda from skfda import FDataGrid from s

我有一些R代码,我正试图在Python中复制它们。在R文件中,我有一个数据帧,我用

smoothedTime <- ksmooth(1:length(df$time), df$time, bandwidth=100, x.points=(1:length(df$time)))$y
结果仍然不同。我想知道为什么我得不到同样的答案,我能做些什么才能得到同样的答案

有关守则如下:

Python代码:

import skfda
from skfda import FDataGrid
from skfda.misc import kernels
import skfda.preprocessing.smoothing.kernel_smoothers as ks

myTime = [-0.01, -0.02, -0.01, -0.01, -0.04, -0.05, -0.07, -0.1, -0.12, -0.15, -0.19, -0.22, -0.26, -0.27, -0.31, -0.33, -0.36, -0.38, -0.4, -0.42, -0.44, -0.44, -0.46, -0.47, -0.48, -0.49, -0.5, -0.49, -0.51, -0.51, -0.51, -0.51, -0.5, -0.48, -0.48, -0.46, -0.45, -0.43, -0.41, -0.39, -0.37, -0.34, -0.34, -0.32, -0.31, -0.32, -0.35, -0.35, -0.37, -0.39, -0.42, -0.45, -0.5, -0.52, -0.55, -0.58, -0.6, -0.6, -0.6, -0.6]
fd = FDataGrid(sample_points=[*range(1, len(myTime)+1)],
           data_matrix=[myTime])
smoother = ks.NadarayaWatsonSmoother(smoothing_parameter=100)
smoothed = smoother.fit_transform(fd)
R代码:

df$time <- c(-0.01, -0.02, -0.01, -0.01, -0.04, -0.05, -0.07, -0.1, -0.12, -0.15, -0.19, -0.22, -0.26, -0.27, -0.31, -0.33, -0.36, -0.38, -0.4, -0.42, -0.44, -0.44, -0.46, -0.47, -0.48, -0.49, -0.5, -0.49, -0.51, -0.51, -0.51, -0.51, -0.5, -0.48, -0.48, -0.46, -0.45, -0.43, -0.41, -0.39, -0.37, -0.34, -0.34, -0.32, -0.31, -0.32, -0.35, -0.35, -0.37, -0.39, -0.42, -0.45, -0.5, -0.52, -0.55, -0.58, -0.6, -0.6, -0.6, -0.6)
smoothedTime <- ksmooth(1:length(df$time), df$time, kernel="normal", bandwidth=100, x.points=(1:length(df$time)))$y

df$time这种行为的原因是R中的
ksmooth
函数对不同的内核具有不同的缩放比例(请参见),而scikit fda只是在应用内核之前除以传递的bandwith。如果将
平滑_参数
乘以
0.3706506
(对于普通内核)或
0.5
(对于盒式内核;请注意,此内核也可以在scikit fda中使用,传递参数
kernel=skfda.misc.kernels.uniform


免责声明:我是scikit fda的维护者。很抱歉,我的回答太晚了,但是当一个问题出现在这个页面上时,我没有得到通知。如果您将来对软件包有疑问,可以尝试打开或打开。我收到这些通知,通常可以在几个小时或几天内回答。

无需担心响应时间。谢谢
df$time <- c(-0.01, -0.02, -0.01, -0.01, -0.04, -0.05, -0.07, -0.1, -0.12, -0.15, -0.19, -0.22, -0.26, -0.27, -0.31, -0.33, -0.36, -0.38, -0.4, -0.42, -0.44, -0.44, -0.46, -0.47, -0.48, -0.49, -0.5, -0.49, -0.51, -0.51, -0.51, -0.51, -0.5, -0.48, -0.48, -0.46, -0.45, -0.43, -0.41, -0.39, -0.37, -0.34, -0.34, -0.32, -0.31, -0.32, -0.35, -0.35, -0.37, -0.39, -0.42, -0.45, -0.5, -0.52, -0.55, -0.58, -0.6, -0.6, -0.6, -0.6)
smoothedTime <- ksmooth(1:length(df$time), df$time, kernel="normal", bandwidth=100, x.points=(1:length(df$time)))$y