Back to questions
JuniorTheoryCommon
What happens when this program runs?
import numpy as np
from sklearn.cluster import AgglomerativeClustering
X = np.array([[0], [1], [10], [11]])
model = AgglomerativeClustering(n_clusters=2).fit(X)
print(model.predict(np.array([[2]])))predict raises AttributeError: this class defines no predict method
- Expecting the new point to join the nearest cluster: the merge tree covers only the fitted points, so the class has no
predictat all; usefit_predictorlabels_. - Expecting
NotFittedError: the model is fitted andlabels_is set; the call fails before any check, because the class defines nopredictmethod.
- How would you assign new customers to segments found by agglomerative clustering?
- Which clustering class in scikit-learn does have a
predictmethod, and what does it compare a new point with?