Skip to content

rbf with gaussian kernel seems to produce more noise than original data #4523

@eyurtsev

Description

@eyurtsev

This is probably user error, but I can't get rbf interpolation working in scipy. (I tried reading through the code, but it's a bit difficult to figure out what's going on...)

Basically, the more x data points I add the noisier the interpolation gets:

illustration

Below is a short script showing the problem.

I used sklearn's KneighborsRegressor to show what I expected to see as my output. I also re-implemented the same thing myself which gives identical output to that of sklearn (not included below.)

I am on scipy 0.15.1.

%pylab inline
import scipy
from scipy.interpolate import Rbf
from sklearn.neighbors import KNeighborsRegressor

# Generate some data
x = np.linspace(0, 10, 50)
z = x + 4.0 * randn(len(x))

# plot data
scatter(x, z, color='black', label='data')

# RBF regression using sklearn. Use all neighbors and gaussian kernel
def weights_func(dist_array):
    return exp(-dist_array**2)

est = KNeighborsRegressor(n_neighbors=50, weights=weights_func)
est.fit(x.reshape(-1, 1), z)
ym = est.predict(x.reshape(-1, 1))
plot(x, ym, color='purple', linestyle='-', linewidth=2, label='rbf using KneighborsRegressor')


# Rbf from scipy
rbf = Rbf(x, z, function='gaussian', epsilon=1)
plot(x, rbf(x), label='scipy-rbf')
legend(loc='center left', bbox_to_anchor=(1.05, 0.5), frameon=False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions