So we initialize the algorithm by putting

two points that will be used as the initial means of two clusters.

So the middle diagram, the red and the blue are the two initial means.

And these two initial means, this collection of samples of

sounds get clustered in the way that we see here with the red cluster and

the cyan cluster.

And now, with K-means, we iterate over this

minimization that, this equation that we have here.

And after a certain iteration, it converges,

and it converges to the clustering that we have on the right.

So it has clustered the red dots in the lower left corner and

the cyan dots in the upper right corner.

And clearly, this is a much better clustering than the initial

random clustering that the algorithm started with.

So now, with that, we can have collections of sounds and

automatically find classes that group sounds

that might have a similar audio features.

The last thing that we talked about for

describing sound collections is the classification of sound.

And that means that we know some classes.

We have identified certain categories of sounds.

And what we want to do is given a new sound,

we want to classify to one of these known classes.

So the K nearest neighbors classifier, KNN,

is an algorithm used for this type of classification.

And the rule of that we implement with KNN,

it classifies a sound by assigning to it the class

that is most frequent in the neighbors.

So we find K neighbors, and whatever is the majority vote of those neighbors

then becomes the class of this query or of this new sound.

So this block diagram exemplifies this process,

these set of rules that are implemented in the KNN algorithms.

So we start from a query, okay so that would correspond to a new sound, and

we are starting with target examples.

So we are starting with collection of samples, of sounds that have a label.

For example, in the diagram below, we have two such collections,

label collections, the blue and the red ones.

And the cyan dots are our query.

So we have to label or assign these query samples to one of these two collections.

So what we do is we measure the distance with the Euclidean distance.

We measure from every query sample to all the neighbors, okay?

And we take the K top results.

So we only look at the K nearest neighbors.