You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to integrate a "predict" function, which allows for the prediction of labels on new data? Currently, to do this task I'm using a nearest neighbor search but that's particularly inefficient. I might work on building this for myself from your codebase if my schedule is forgiving!
I have put some thought in to this, and sadly it is more complicated than I would like. Issues #34 and #38 are closely related. So first the good news: this is entirely possible, and the method mentioned in #34 is actually quite workable. I have even implemented it for a a custom application elsewhere. It is slower than I would like, but still fairly fast (and I haven't really optimized it). The bad news: I don't know how to make this work with the sklearn API. The catch is that, if done "correctly" the result of predict potentially creates a new clustering (suppose the new point is just enough to connect two previously separate clusters, or re-weights the condensed tree in such a way that a new flat clustering is now preferred) and so the result is a label for the new point with respect to what is actually potentially an entirely new clustering and labelling of all the old points -- if I just return a label then it will be confusing because it won't match the prior labelling that you have, but the API doesn't leave room to return a label for the new point and the new labelling for all the original points. Perhaps I'll try and chat with the sklearn folks and see what they have to say about the best approach to this. Do you have any thoughts about how you would like to see this work?
According to me a such predict function is ill-posed. HDBSCAN assumes nothing about the data : at the very least it assumes that there is a density and try to catch it through the single_linkage_tree and condensed_tree. This problem arises when we try to explain the difference between transductive learning and inductive learning. The first will only give you the label of the data you have when the second learn a model from it. So the first cannot predict anything since it catches only the labels for the "training" data when the second fits a mapping for the whole data space.
As a evidence of this, take a look at the DBSCAN documentation on SciKit. There is also no function predict for the same reason.
HDBSCAN is a really cool algorithm, especially because we don't need the number of clusters when we use it. But nothing is free, HDBSCAN is highly transductive, it uses the whole dataset to cluster it from nowhere (like SVM, it didn't use the density, only a coarse estimate but SVM assumes linear separation), the price to pay is that you have no model so no possibility of prediction at all.
On the page on semi-supervised learning of Wikipedia you can read this sentence which shows the picture :
"Intuitively, we can think of the learning problem as an exam and labeled data as the few example problems that the teacher solved in class. The teacher also provides a set of unsolved problems. In the transductive setting, these unsolved problems are a take-home exam and you want to do well on them in particular. In the inductive setting, these are practice problems of the sort you will encounter on the in-class exam."
I think that's a fair view. What I'm describing fits better with an update
method than a predict method, since it actually updates (and potentially
changes) the whole model. This may in fact be the best answer.
Given the desire for it, however, it might be useful to see if I can come
up with a suitable external function (rather than a predict method) which
can give "estimates" (rather than model predictions) of what cluster a
certain new point might belong to.
According to me a such predict function is ill-posed. HDBSCAN assumes
nothing about the data : at the very least it assumes that there is a
density and try to catch it through the single_linkage_tree and
condensed_tree. This problem arises when we try to explain the difference
between transductive learning and inductive learning. The first will only
give you the label of the data you have when the second learn a model from
it. So the first cannot predict anything since it catches only the labels
for the "training" data when the second fits a mapping for the whole data
space.
As a evidence of this, take a look at the DBSCAN documentation on SciKit.
There is also no function predict for the same reason.
HDBSCAN is a really cool algorithm, especially because we don't need the
number of clusters when we use it. But nothing is free, HDBSCAN is highly
transductive, it uses the whole dataset to cluster it from nowhere (like
SVM, it didn't use the density, only a coarse estimate but SVM assume
linear separation), the price to pay is that you have no model so no
possibility of prediction at all.
On the page on semi-supervised learning page of Wikipedia you can read
this sentence which shows the picture :
"Intuitively, we can think of the learning problem as an exam and labeled
data as the few example problems that the teacher solved in class. The
teacher also provides a set of unsolved problems. In the transductive
setting, these unsolved problems are a take-home exam and you want to do
well on them in particular. In the inductive setting, these are practice
problems of the sort you will encounter on the in-class exam."
I clearly understand the desire for this kind of function, you are right to put it in an other function. If later you need to respect the SciKit standard, warn people about this ill-posed problem will be important.
The issue is the following question : "Will this new point (for which we want only to predict) create a configuration where a new cluster must be created in which it belongs ?" . This question is in fact a transductive one since you need to consider the whole new dataset to get the answer, indeed : if the answer is yes, you have to modify the labels of the "training" set.
However maybe you can just look at the min_cluster_size-1 nearest and assign the label of the nearest labeled (not as noise) neighbor such that the distance to the cluster is less than 1/ \lambda_min or else noise. This way you are like predicting from the coarse estimate of the density of the cluster without changing this estimate.
You can't do more than that because after you need to modify the other labels to have a consistent result.
Looking back over how the algorithm works, I agree that how the "predict" algorithm works for SciKit-Learn is ill-proposed for the HDBScan algorithm, since it requires re-weighting the condensed tree. However there is a different interpretation that could be useful.
If instead of proposing all the data to HDBSCAN, each new point is proposed independently of the other points in the new data set (so that the clustering is affected infinitesimally), the new data could be labeled by the condensed tree. This is useful most notably for outlier detection and clustering on a reduced space (for very large data sets HDBScan is unwieldy, so creating a reduced dictionary, clustering on that dictionary, and then being able to expand to the larger data set is a useful tool).
I don't disagree with the utility, I'm just wary of doing something that is potentially subtly not what the user expects. There are a few different ways of doing this, and your proposal is quite useful (as it retains the original clusters and is probably doable (I have to think through all the details carefully). I may simply add a small suite of utility functions that can provide these sorts of functionality. I have a few other pressing matters right now, but I'll try to get to this when I get some time available.
Activity
lmcinnes commentedon Aug 26, 2016
I have put some thought in to this, and sadly it is more complicated than I would like. Issues #34 and #38 are closely related. So first the good news: this is entirely possible, and the method mentioned in #34 is actually quite workable. I have even implemented it for a a custom application elsewhere. It is slower than I would like, but still fairly fast (and I haven't really optimized it). The bad news: I don't know how to make this work with the sklearn API. The catch is that, if done "correctly" the result of predict potentially creates a new clustering (suppose the new point is just enough to connect two previously separate clusters, or re-weights the condensed tree in such a way that a new flat clustering is now preferred) and so the result is a label for the new point with respect to what is actually potentially an entirely new clustering and labelling of all the old points -- if I just return a label then it will be confusing because it won't match the prior labelling that you have, but the API doesn't leave room to return a label for the new point and the new labelling for all the original points. Perhaps I'll try and chat with the sklearn folks and see what they have to say about the best approach to this. Do you have any thoughts about how you would like to see this work?
Pantamis commentedon Aug 26, 2016
According to me a such predict function is ill-posed. HDBSCAN assumes nothing about the data : at the very least it assumes that there is a density and try to catch it through the single_linkage_tree and condensed_tree. This problem arises when we try to explain the difference between transductive learning and inductive learning. The first will only give you the label of the data you have when the second learn a model from it. So the first cannot predict anything since it catches only the labels for the "training" data when the second fits a mapping for the whole data space.
As a evidence of this, take a look at the DBSCAN documentation on SciKit. There is also no function predict for the same reason.
HDBSCAN is a really cool algorithm, especially because we don't need the number of clusters when we use it. But nothing is free, HDBSCAN is highly transductive, it uses the whole dataset to cluster it from nowhere (like SVM, it didn't use the density, only a coarse estimate but SVM assumes linear separation), the price to pay is that you have no model so no possibility of prediction at all.
On the page on semi-supervised learning of Wikipedia you can read this sentence which shows the picture :
"Intuitively, we can think of the learning problem as an exam and labeled data as the few example problems that the teacher solved in class. The teacher also provides a set of unsolved problems. In the transductive setting, these unsolved problems are a take-home exam and you want to do well on them in particular. In the inductive setting, these are practice problems of the sort you will encounter on the in-class exam."
I hope it helps
lmcinnes commentedon Aug 26, 2016
I think that's a fair view. What I'm describing fits better with an update
method than a predict method, since it actually updates (and potentially
changes) the whole model. This may in fact be the best answer.
Given the desire for it, however, it might be useful to see if I can come
up with a suitable external function (rather than a predict method) which
can give "estimates" (rather than model predictions) of what cluster a
certain new point might belong to.
On Fri, Aug 26, 2016 at 3:11 AM, Pantamis notifications@github.com wrote:
Pantamis commentedon Aug 26, 2016
I clearly understand the desire for this kind of function, you are right to put it in an other function. If later you need to respect the SciKit standard, warn people about this ill-posed problem will be important.
The issue is the following question : "Will this new point (for which we want only to predict) create a configuration where a new cluster must be created in which it belongs ?" . This question is in fact a transductive one since you need to consider the whole new dataset to get the answer, indeed : if the answer is yes, you have to modify the labels of the "training" set.
However maybe you can just look at the
min_cluster_size-1nearest and assign the label of the nearest labeled (not as noise) neighbor such that the distance to the cluster is less than 1/ \lambda_min or else noise. This way you are like predicting from the coarse estimate of the density of the cluster without changing this estimate.You can't do more than that because after you need to modify the other labels to have a consistent result.
tobyfrancis commentedon Aug 29, 2016
Looking back over how the algorithm works, I agree that how the "predict" algorithm works for SciKit-Learn is ill-proposed for the HDBScan algorithm, since it requires re-weighting the condensed tree. However there is a different interpretation that could be useful.
If instead of proposing all the data to HDBSCAN, each new point is proposed independently of the other points in the new data set (so that the clustering is affected infinitesimally), the new data could be labeled by the condensed tree. This is useful most notably for outlier detection and clustering on a reduced space (for very large data sets HDBScan is unwieldy, so creating a reduced dictionary, clustering on that dictionary, and then being able to expand to the larger data set is a useful tool).
lmcinnes commentedon Aug 29, 2016
I don't disagree with the utility, I'm just wary of doing something that is potentially subtly not what the user expects. There are a few different ways of doing this, and your proposal is quite useful (as it retains the original clusters and is probably doable (I have to think through all the details carefully). I may simply add a small suite of utility functions that can provide these sorts of functionality. I have a few other pressing matters right now, but I'll try to get to this when I get some time available.
lmcinnes commentedon Feb 16, 2017
This has now landed in master. There are two relevant functions:
approximate_predict
which will give the clusters an array of new points would be assigned to and
membership_vector
which will give a soft clustering vector of probabilities of membership of clusters.
Please take an opportunity to try it out and provide feedback as it is all still somewhat experimental at this time.