Visualization of Decision Tree(Machine Learning)(Python , Sklearn , Graphviz )
What is Decision Tree ?
Decision Trees are a non-parametric supervised learning method used for classification and regression. The goal is to create a model that predicts the value of a target variable by learning simple decision rules inferred from the data features . It is a very specific type of probability tree that enables you to make a decision about some kind of process.
Decision Trees, which are an example of a nonparametric machine learning algorithm. if we talk about logistic regression which give us coefficients of a line . here these coefficients are called parameter. Decision Trees won’t be defined by a list of parameters ,So Decision Tree is a nonparametric machine learning algorithm.
So now without going into theory part , I assume if you are here then you will definitely know about , On what basic we create Decision tree like Gini impurity , Entropy , Information gain etc..
Now we will see , How we generate a Decision Tree. So we have to install modules which is required for us (for Windows)
first we install sklearn
pip install -U scikit-learn
now we install Graphviz
pip install graphviz
or, you can direct install .exe file from official website of Graphviz click here
After doing all of this Now we write code in python , our codes look like this
After running this python code you can see a new file tree.dot is created (which is returned by function export_graphviz)
Now we are in final stage , Now we have to generate a image thorough this tree.dot file
Now Open command Prompt in that folder and type command
dot -Tpng tree.dot -o OutputFile.png
Finally, You can see our Decision tree is created what we want.
Thank you, Happy learning….