#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.
0 Comments
Leave a Reply. |