I'm using Sklearn's KNN to build a classifier and was wondering if there is any way to visualize the decision tree that the algorithm builds. Maybe something of this fashion
2 Answers
$k$-NN does not build a decision tree to classify a new instance, it looks at the class of the most similar examples (the nearest neighbours) in the training set. So, in short, no you cannot get a decision tree from $k$-NN. You can build a decision tree for your dataset directly by using scikit-learn's DecisionTreeClassifier
instead if you need a decision tree.
-
$\begingroup$ Ok, thank you. This explains a lot! I had this constant confusion that the K-nn is supposed to build a decision tree, but now I get it $\endgroup$ Commented Apr 4, 2018 at 14:23
You can obtain dendrograms in other algorithms of clustering, concretely hierarchical clustering. May be you talk about that, it's not a decision, but have a similar appearance.