The output from tree classification by package tree of a class target field with several class values looks like this:
30-39 40-49 50-59 60plus to29
1 0.1723497 0.2145071 0.5151891 0.02588345 0.07207068
2 0.1451786 0.1370050 0.2740099 0.32061886 0.12318770
4 0.1723497 0.2145071 0.5151891 0.02588345 0.07207068
But I want the result to be in the way:
1 50-59
2 60plus
4 50-59
Are there any implemented functions (I have not found any) that will provide this output automatically or do I have to write an R function?
This function has to fetch the max value of each line, get the index of the matched value in this line and then provide the age class of this index, like 60plus.
In the
predictfunction there is a parameter calledtype. It defines the type of output you want for the prediction.Just do
And you will get the class of higher probability.
See the reference manual for further informations. (predict.tree function)