This algorithm determines predicts the label of an instance from the mean of the labels 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