“Data Smoothing with the Nadaraya-Watson Kernel Technique Using C#” in Visual Studio Magazine

I wrote an article titled “Data Smoothing with the Nadaraya-Watson Kernel Technique Using C#” in the November 2026 edition of Microsoft Visual Studio Magazine. See https://visualstudiomagazine.com/articles/2026/11/03/data-smoothing-with-the-nadaraya-watson-kernel-technique-using-c-sharp.aspx.

Nadaraya-Watson (NW) kernel smoothing is a classical statistics technique that removes noise in a dataset by using weighted averages to reveal patterns.

NW kernel smoothing uses a kernel function (often RBF) that measures the similarity between two vectors. The RBF kernel function bandwidth parameter controls the degree of smoothing.

NW kernel smoothing can be applied to both single-dimensional and multidimensional data.

I put together a demo to explain how the technique works. The demo source data is:

0.1000, 0.1000, 0.0998
0.2000, 0.2000, 0.3987
0.3000, 0.3000, 0.0955
0.5000, 0.5000, 0.5794
0.6000, 0.6000, 0.5646
0.7000, 0.7000, 0.9442
0.9000, 0.9000, 0.4833
1.0000, 1.0000, 0.5415

The programmatic output of the demo is:

Begin Nadaraya-Watson kernel smoothing demo

Loading simple XXy data
Done

First three data X:
  0.1000  0.1000
  0.2000  0.2000
  0.3000  0.3000

First three data y:
  0.0998
  0.3987
  0.0955

Creating NW kernel smoother with RBF sigma = 0.1600
Done

Computing smoothed y values
Done

   X             y        smooth y
-------------------------------------
  0.10  0.10    0.0998    0.2069
  0.20  0.20    0.3987    0.2303
  0.30  0.30    0.0955    0.2474
  0.50  0.50    0.5794    0.5599
  0.60  0.60    0.5646    0.6681
  0.70  0.70    0.9442    0.7357
  0.90  0.90    0.4833    0.5556
  1.00  1.00    0.5415    0.5255

End NW kernel smoothing demo

Data smoothing is most often used with small datasets that have a single x value and a single y value. This allows the source data and the smoothed data to be visualized using a graph. However, I used data with two x values, such as (0.10, 0.10), where both values are artificially the same, to demonstrate that NW kernel smoothing can use multidimensional X data with several values. The following graph uses just the first element of each x vector so that the data can be displayed in a 2D graph:

When using NW kernel smoothing, you must specify a kernel function and its parameter or parameters. There are many different kernel functions.

The demo uses the radial basis function (RBF) kernel, with a sigma parameter set to 0.16. Smaller values of sigma produce a more jagged approximation of the source data, and larger values produce a smoother approximation. Data smoothing is subjective, and the choice of a good RBF sigma value will vary from problem to problem.

Nadaraya-Watson kernel smoothing is named after Elizbar Nadaraya (born 1936, Soviet Georgia) and Geoffrey Watson (1921-1998, Australia), who came up with the idea independently in 1964. Their original intent was to use the technique for regression rather than data smoothing.

It is possible to use the ideas in NW kernel smoothing to perform regression. Instead of computing smoothed values for existing X data points, you can compute a predicted (smoothed) value for a new, previously unseen X data point.



Actor Russell Johnson (1924-2014) is best known for his role as the Professor on the “Gilligan’s Island” TV series (1964-67). Johnson also appeared in three of my favorite science fiction films of the 1950s.

Left: In “Attack of the Crab Monsters” (1957), a scientific expedition on a remote Pacific island runs into a pair of huge, intelligent, evil crabs (accidentally produced by atomic testing). Low-budget but an effective film. My grade = B.

Center: In “This Island Earth” (1955), aliens from the planet Metaluna recruit Earth scientists in an effort to convert lead to uranium, which is deperately needed in a war with the Zagons. My grade = B+.

Right: In “It Came from Outer Space” (1953), an alien spacecraft crash lands in the Southwest desert. Aliens capture people from the local town to help them repair their ship. They succeed and there’s a happy ending. My grade = A-.


This entry was posted in Miscellaneous. Bookmark the permalink.

Leave a Reply