# Class "interpolation" (distance to classes)

**URL:** <https://discourse.flucoma.org/t/class-interpolation-distance-to-classes/1903>\
**Category:** Usage Questions\
**Created:** [May 7, 2023, 12:34pm UTC](https://discourse.flucoma.org/t/class-interpolation-distance-to-classes/1903 "2023-05-07T12:34:08Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![rodrigo.constanzo](https://discourse.flucoma.org/user_avatar/discourse.flucoma.org/rodrigo.constanzo/32/12_2.png) [@rodrigo.constanzo](https://discourse.flucoma.org/u/rodrigo.constanzo)\
**Post date:** [May 7, 2023, 4:32pm UTC](https://discourse.flucoma.org/t/class-interpolation-distance-to-classes/1903/4 "2023-05-07T16:32:49Z")

</div>

I’ll start with clarifying my intention/desire as the whole kmeans/kdtree/knearestdist/etc… is me just trying to make my way to that. I don’t have a specific interest in computing means etc…

The most standard use case here would be would be to train ~50 hits on the center of the drum, and label that as `classA`, and then train ~50 hits near the edge of the drum, and label that as `classB`. I’ve got this part working well and fairly refined.

Now what I want to do is hit the drum anywhere and have it, effectively, give me the “radius” from the center where I’ve hit the drum by telling me whether I’m closer to `classA` or `classB`. In a really simplistic way, something like this:

 ![circles](https://discourse.flucoma.org/uploads/default/original/2X/d/dc7da3a193f11888ac7b7da92f5fdd3243e617ab.jpeg)

So in this case hitting dead center on the drum would tell me that the hit was 100% `classA` and report a value for that (`0.0` in this case), and if I hit near the edge, it would be 100% `classB` and it would return `1.0`.

Or something along the lines of this, with a single value reporting where on the spectrum between `classA` or `classB` a new sound is:  
 ![Screenshot 2023-05-07 at 5.14.04 PM](https://discourse.flucoma.org/uploads/default/original/2X/0/05602150d4355a5e45d8acfd56e3192e5ea3c56d.png)

This is what I would like to do, as a core use case.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

> [@tremblap](#):
>
> > [@rodrigo.constanzo](#):
> >
> > The second problem is once the above is solved, presumably the next step is creating a KDTree with two entries, `classA` and `classB`.
> 
> that is literally what knnclassifier is doing. so the best way forward for you I think is not your proposed workflow but this one:

I initially thought I could do this directly in the classifier, as it has a KDTree, and is computing distances etc… so if there’s a way to skip all the kmeans/means/kdtree stuff, I’m all for it!

For the life of me, however, I couldn’t figure out how to do that.

(having a quick look through @jacob.hart’s [article](https://learn.flucoma.org/explore/harker/) on @a.harker’s piece, and it looks like @a.harker made a build of the object that spits out the “hotness” of each of the classes, so I guess the native/vanilla build does not do that (it would be useful as it looks like exactly what I’m looking for here!))

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

> [@tremblap](#):
>
> there is. kmeans dump has that for you as you said but you could probably enter your own class in there and “train” for one iteration and it will optimise the centroids. It is worth a try.

Not sure I’m following this part.

In my case I know exactly what the classes should be, so I wouldn’t want `fluid.kmeans~` to mess with that at all. I have 50 hits of `classA` and 50 hits of `classB`, which I label/train up in `fluid.knnclassifer~` (and `fluid.mlpclassifier~`).

> [@Using MLPregressor to get the confidence vector of MLPclassifier](https://discourse.flucoma.org/t/using-mlpregressor-to-get-the-confidence-vector-of-mlpclassifier/1387/1):
>
> Dear all Someone asked on our [GitHub](https://github.com/flucoma/flucoma-sc/issues/92) if it was possible for FluidMLPClassifier to provide its confidence vector. The answer is that there is another way: since the MLP code is the same under the hood, one can load a model made in the classifier in the regressor and get access to the output vector, in effect a histogram of how much each class is likely to be the right one. Here it is in Max first - I am using the demo code from the classifier tutorial. I will code the SC version later from the …

Hmm, I think this may do the trick here. Would this also work with `fluid.knnclassifier~` + `fluid.knnregressor~`? At the moment I’m training a knn classifier as the default since it’s a single-click operation and works “fine”, with the MLP one being optional.

edit:  
It does _not_ seem to do the trick. Or if it does, I can’t figure out what level of `dump` to send `fluid.knnregressor~` from `fluid.knnclassifier~` without it returning an `invalid JSON format` error.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I imagine this shit has long since sailed, but out of curiosity, why don’t the classifiers spit out this info? I always assumed they did, and I hadn’t really gotten around to making use of it yet. And I would have never thought to do what that thread suggests (dump the classifier into a regressor to get the confidence…).

---

_[View the full topic](https://discourse.flucoma.org/t/class-interpolation-distance-to-classes/1903)._
