Weighted clustering using NearestNeighbors
If you have an inverted index, enforcing a certain value to be required, while having other values optional and only used for similarity should be straightforward. Just think of the full-text search example with required and optional terms.
Depending on how many queries you do, linear search as well as a "group by" approach may be fine.
I have a use case where in I need to cluster N transactions but with a constraint that a particular column value in the resultant clusters should be same for individual clusters. I have been using NearestNeighbors - NN from sklearn for this purpose and it seems to workout to an extend. The distance metric chosen is Cosine and the the type of data is categorical - one hot encoding is done before actual clustering.
Now if I have columns c1, c2...cn, which is used along with NN for clustering and if I want to enforce the criteria that for a particular cluster derived, Gi, there should be a single unique value for column cx with in Gi. How would I enforce this?
I went through a couple of documents and some of the techniques indirectly suggests to groupby the column cx and then do the clustering or duplicate the column cx in data and cluster. Are these valid approached to tackle the problem?