![]() ![]() #Print the actual labels of each test point We will use Python’s sklearn library to build a decision tree classifier from sklearn import treeĭtClassifier = tree.DecisionTreeClassifier()ĭtClassifier.fit(train_data, train_target) Test_data = iris.data 3) Training and testing the decision tree classifier Train_data = np.delete(iris.data, test_indices, axis=0) Train_target = np.delete(iris.target, test_indices) #Choose top 2 examples of each flower type as test rows So we will split our dataset into two parts. In any machine learning algorithm we need to train the model on a set that is very different from the dataset on which it is tested. This matches with the wikipedia screenshot pasted in the dataset section above. Print("Virginica flower 1 - ",iris.data,"\n") Print("Versicolor flower 1 - ",iris.data) Print("Feature Names - ", iris.feature_names,"\n") Wikipedia gives these features Features extracted by Python from the actual dataset #Print the row 0,50 and 100 i.e. Let’s load the data into the memory, look at the features and print a few examples of each class of flower. Code Walkthrough 1) Loading and taking a peek at the data Now let’s start building the code needed for constructing our decision tree. Class 2 stands for Virginica and takes up rows 100–149.Class 1 stands for Versicolor and takes up rows 50–99.Class 0 stands for Setosa and takes up rows 0–49.All we need to start coding is that there are 150 rows in the dataset, 50 per type of iris. One can go over there and study the dataset in depth. Wikipedia mentions the complete details of the data set. For example, from the images above we can clearly see that the Virginica petals are much wider than Setosa petals and a quick look at the data corroborates that observation. The features that we have for each of these types of iris are going to help us differentiate between them. What we want to do with decision tree is to differentiate these 3 types of iris - Iris Setosa, Iris Versicolor and Iris Virginica - based on the features. This data set lists a few features - sepal and petal lengths, and widths - of 3 different types of iris flower. We are going to use the Iris flower dataset. ![]()
0 Comments
Leave a Reply. |