Machine Learning with Python – Decision Tree
?Machine learning is a branch of Artificial Intelligence.
?An Early Example of Machine Learning is …
?..Deep Blue; it was a software designed to play chess game, but that’s all it could do.
?Evolution of Machine Learning
?Some questions sounds quite easy but we can’t answer them by writing a programme, like “what is the difference between apple and orange?†for these types of questions, machine learning is the best.
?How machine learning answers these questions is by identifying features for e.g. weight of apple and orange, size etc..
Types Of Classifiers
?Artificial Neural network
?Support Vector Machine
?Linear Classifiers: Logistic Regression, Na?ve Bayes Classifier
?Random Forest
?Boosted Trees
?Decision Tree etc.
But we are using decision trees first because it is easy to understand.
?Machine Learning with Decision Tree Classifier can have number of applications;
?For example identifying if the image is black or white etc.
How it Works!
?Classifier takes some input and then assigns to it an output.
?In our example we are defining two features and a label.
?The data contains the weight and texture (features) for the label apple or orange.
?Labels is the last columns that contains the fruit name.
?If there is apple we take 0 and if orange then 1 similarly if the shape is smooth it means its apple and so we assign 1 and if bumpy then we assign 0.
Recipe for Supervised Learning Model
Training Data
Decision Tree
?In scikit the training algorithm is included in the classifier object, and it is called fit.
?We can think of Fit as synonym for “Find pattern in dataâ€.
Working Program
?Now we are asking our short machine learning program to predict, we will be providing features and it will be outputting labels.
?Feature we defined is “(150, 0)â€, Remember, 0 represents bumpy and 1 represents smooth, so our arguments define that the weight for the label is 150 and the shape is 0 i.e. bumpy.
?We think that the output should be Orange, and binary representation for this is ‘1’. Lets see what our program outputs.
Program Output
?The output is 1, that means our program now predicts well.
Another Example
A bit more complex example is "Iris" data set that is about 3 types of flowers "Setosa, Versicolor and verginicia".
Goal for this dataset:
?Import dataset
?Train a classifier
?Predict label for new flower
?Visualize the tree
The process of importing, training and predicting would remain same as discussed above.
Decision Tree Diagram
You can also print decision tree diagram of the model for any given data set. This is the decision tree diagram for Iris data set.
Hope Now You Have Improved Understanding of Decision Tree :)
May you have any queries, feel free to contact us. https://www.custech2.com/
Thank You
Prepared by: Kumail Raza and Hadi Rajani (BI and Business Analytics Practitioners)