


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Decision trees are among the simplest simple machine learning algorithms, and they can be employed for both classification and regression. After viewing, you'll be able to construct a decision tree classifier from scratch. The following is how the article is organised: An Overview of Decision Trees The Science of Decision Trees Crash Course Recursion Complete Implementation Conclusion An Overview of Decision Trees Decision trees are a non-parametric model that can be used for regression and classification. The from- scratch implementation will take some time to grasp, but the algorithm's logic is straightforward. Decision trees are made up of only two components: nodes and branches. In a moment, we'll go over the various types of nodes. If you decide to follow along, the term recursion should not feel foreign to you because the algorithm is based on it. There are various types of nodes: The root node is the node at the top of the tree. It has a feature that best divides the data (a single feature that alone classifies the target variable most accurately) Decision nodes are nodes that evaluate variables. There are arrows pointing to and away from these nodes. Leaf nodes are the final nodes where the prediction is made. Depending on the size of the dataset (both in rows and columns), there are probably thousands to millions of different ways to arrange the nodes and their conditions. So, how do we locate the root node?
How to Find the Root Node In a nutshell, we must examine how each input feature independently classifies the target variable. If none of the features is completely correct in the classification, we can consider them impure. We can use the Entropy metric to determine which of the impure features is the most pure. We'll go over the formula and calculations later, but keep in mind that the entropy value ranges from 0 (best) to
The _build(X, y, depth) function builds a decision tree recursively until the stopping criteria is met (hyper parameters in the constructor) The fit(X, y) function invokes the _build () function, which returns the constructed tree to the function Object () { [native code] }. The _predict(x) function searches the tree for a single instance to classify. Predict(X) calls the _predict () function on each instance in matrix X. There's no denying it's a lot. Take your time understanding each line of the code below. It's well- documented, so the following comments should help: You are not expected to comprehend every line of code in a single sitting. Give it some time, go through the code line by line, and try to figure out why things work. It's not that difficult once you understand the algorithm's basic intuition. Conclusion: Naturally, it will take you at least a couple of readings to fully comprehend the subject. Please feel free to look into additional resources as they will help you understand more. You now understand how to build the Decision tree classifier algorithm from the ground up. Is this to say you should abandon the de facto standard machine learning libraries? No way, no how. Let me explain. You now understand how to build the Decision tree classifier algorithm from the ground up. Is this to say you should abandon the de facto standard machine learning libraries? No way, no how. Let me explain. You should not write something from scratch just because you can. Nonetheless, knowing every detail of how algorithms work is a valuable skill that can set you apart from every other fit and predict data scientist. Thank you for reading.