This algorithm predicts the true value of an instance from the mean of the values of the k nearest instances in the training set.

val clf = new kNNRegressor(k=40)

Here is its performance on the cubic dataset.

Nonlinear test