官术网_书友最值得收藏!

Decision tree

Breiman and Quinlan mainly developed decision trees, which have evolved a lot since the 1980s. If the dependent variable is continuous, the decision tree will be a regression tree and if it is categorical variable, it will be a classification tree. Of course, we can have a survival tree as well. Decision trees will be the main model that will be the beneficiary of the ensemble technique, as will be seen throughout the book.

Consider the regression tree given in the following diagram. We can see that there are three input variables, which are Decision tree, and the output variable is Y. Strictly speaking, a decision tree will not display all the variables used to build the tree. In this tree structure, a decision tree is conventionally displayed upside down. We have four terminal nodes. If the condition Decision tree is satisfied, we move to the right side of the tree and conclude that the average Y value is 40. If the condition is not satisfied, we move to the left, and check whether Decision tree. If this condition is not satisfied, we move to the left side of the tree and conclude that the average Y value is 100. Upon the satisfactory meeting of this condition, we move to the right side and then if the categorical variable Decision tree, the average Y value would be 250, or 10 otherwise. This decision tree can be captured in the form of an equation too, as follows:

Decision tree
Decision tree
Decision tree

Figure 5: Regression tree

The statistician Terry Therneau developed the rpart R package.

Decision tree for hypothyroid classification

Using the rpart function from the rpart package, we build a classification tree for the same formula as the earlier partitioned data. The constructed tree can be visualized using the plot function, and the variable name is embossed on the tree with the text function. The equation of the fitted classification tree (see Figure Classification Tree for Hypothyroid) is the following:

Decision tree for hypothyroid classification

Prediction and accuracy is carried out in a similar way as mentioned earlier:

> CT_fit <- rpart(HT2_Formula,data=HT2_Train)
> plot(CT_fit,uniform=TRUE)
> text(CT_fit)
> CT_predict <- predict(CT_fit,newdata=HT2_TestX,type="class")
> CT_Accuracy <- sum(CT_predict==HT2_TestY)/nte
> CT_Accuracy
[1] 0.9874213836
Decision tree for hypothyroid classification

Figure 6: Classification tree for Hypothyroid

Consequently, the classification tree gives an accuracy of 98.74%, which is the best of the four models considered thus far. Next, we will consider the final model, support vector machines.

主站蜘蛛池模板: 衡南县| 吴川市| 白水县| 绥中县| 安泽县| 贵州省| 安多县| 沙洋县| 崇信县| 横山县| 宝山区| 延川县| 宜州市| 阳春市| 英德市| 仪征市| 平南县| 苍梧县| 内黄县| 临颍县| 肥城市| 揭东县| 石门县| 泽普县| 定日县| 西峡县| 佛山市| 大名县| 峨眉山市| 鄂尔多斯市| 策勒县| 南陵县| 安新县| 康定县| 梨树县| 柳林县| 阳江市| 大余县| 绥阳县| 镇赉县| 莱西市|