Ordinal Attributes in a Decision Tree Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsDecision tree or logistic regression?Decision tree vs. KNNOrdinal feature in decision treeUnderstanding decision tree conceptForecasting: How Decision Tree work?Decision tree orderingMulticollinearity in Decision TreeDisadvantage of decision tree(Newbie) Decision Tree RandomnessCross Entropy vs Entropy (Decision Tree)

Fundamental Solution of the Pell Equation

Novel: non-telepath helps overthrow rule by telepaths

Why do the resolve message appear first?

How do I find out the mythology and history of my Fortress?

Would "destroying" Wurmcoil Engine prevent its tokens from being created?

Is safe to use va_start macro with this as parameter?

Can a party unilaterally change candidates in preparation for a General election?

8 Prisoners wearing hats

Is it cost-effective to upgrade an old-ish Giant Escape R3 commuter bike with entry-level branded parts (wheels, drivetrain)?

Do I really need recursive chmod to restrict access to a folder?

Where are Serre’s lectures at Collège de France to be found?

How to convince students of the implication truth values?

Closed form of recurrent arithmetic series summation

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

How do pianists reach extremely loud dynamics?

How to down pick a chord with skipped strings?

How do I stop a creek from eroding my steep embankment?

Do square wave exist?

Irreducible of finite Krull dimension implies quasi-compact?

Does classifying an integer as a discrete log require it be part of a multiplicative group?

Is "Reachable Object" really an NP-complete problem?

Ports Showing Closed/Filtered in Nmap Scans

What is this building called? (It was built in 2002)

Find the length x such that the two distances in the triangle are the same



Ordinal Attributes in a Decision Tree



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsDecision tree or logistic regression?Decision tree vs. KNNOrdinal feature in decision treeUnderstanding decision tree conceptForecasting: How Decision Tree work?Decision tree orderingMulticollinearity in Decision TreeDisadvantage of decision tree(Newbie) Decision Tree RandomnessCross Entropy vs Entropy (Decision Tree)










3












$begingroup$


I'm reading the book Introduction to Data Mining by Tan, Steinbeck, and Kumar.
In the chapter on Decision Trees, when talking about the "Methods for Expressing Attribute Test Conditions" the book says :




"Ordinal attributes can also produce binary or multiway splits. Ordinal
attribute values can be grouped as long as the grouping does not
violate the order property of the attribute values. Figure 4.10
illustrates various ways of splitting training records based on the
Shirt Size attribute. The groupings shown in Figures 4.10(a) and (b)
preserve the order among the attribute values, whereas the grouping
shown in Figure a.10(c) violates this property because it combines the
attribute values Small and Large into the same partition while Medium
and Extra Large are combined into another partition."




enter image description here



Why ordinal attribute values can be grouped as long as the grouping does
not violate the order property of the attribute values
?










share|improve this question











$endgroup$




bumped to the homepage by Community 22 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.



















    3












    $begingroup$


    I'm reading the book Introduction to Data Mining by Tan, Steinbeck, and Kumar.
    In the chapter on Decision Trees, when talking about the "Methods for Expressing Attribute Test Conditions" the book says :




    "Ordinal attributes can also produce binary or multiway splits. Ordinal
    attribute values can be grouped as long as the grouping does not
    violate the order property of the attribute values. Figure 4.10
    illustrates various ways of splitting training records based on the
    Shirt Size attribute. The groupings shown in Figures 4.10(a) and (b)
    preserve the order among the attribute values, whereas the grouping
    shown in Figure a.10(c) violates this property because it combines the
    attribute values Small and Large into the same partition while Medium
    and Extra Large are combined into another partition."




    enter image description here



    Why ordinal attribute values can be grouped as long as the grouping does
    not violate the order property of the attribute values
    ?










    share|improve this question











    $endgroup$




    bumped to the homepage by Community 22 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      3












      3








      3


      0



      $begingroup$


      I'm reading the book Introduction to Data Mining by Tan, Steinbeck, and Kumar.
      In the chapter on Decision Trees, when talking about the "Methods for Expressing Attribute Test Conditions" the book says :




      "Ordinal attributes can also produce binary or multiway splits. Ordinal
      attribute values can be grouped as long as the grouping does not
      violate the order property of the attribute values. Figure 4.10
      illustrates various ways of splitting training records based on the
      Shirt Size attribute. The groupings shown in Figures 4.10(a) and (b)
      preserve the order among the attribute values, whereas the grouping
      shown in Figure a.10(c) violates this property because it combines the
      attribute values Small and Large into the same partition while Medium
      and Extra Large are combined into another partition."




      enter image description here



      Why ordinal attribute values can be grouped as long as the grouping does
      not violate the order property of the attribute values
      ?










      share|improve this question











      $endgroup$




      I'm reading the book Introduction to Data Mining by Tan, Steinbeck, and Kumar.
      In the chapter on Decision Trees, when talking about the "Methods for Expressing Attribute Test Conditions" the book says :




      "Ordinal attributes can also produce binary or multiway splits. Ordinal
      attribute values can be grouped as long as the grouping does not
      violate the order property of the attribute values. Figure 4.10
      illustrates various ways of splitting training records based on the
      Shirt Size attribute. The groupings shown in Figures 4.10(a) and (b)
      preserve the order among the attribute values, whereas the grouping
      shown in Figure a.10(c) violates this property because it combines the
      attribute values Small and Large into the same partition while Medium
      and Extra Large are combined into another partition."




      enter image description here



      Why ordinal attribute values can be grouped as long as the grouping does
      not violate the order property of the attribute values
      ?







      machine-learning classification decision-trees






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 1 '18 at 11:40









      Vaalizaadeh

      7,59562264




      7,59562264










      asked Aug 1 '18 at 11:10









      KoinosKoinos

      614




      614





      bumped to the homepage by Community 22 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 22 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          2 Answers
          2






          active

          oldest

          votes


















          0












          $begingroup$

          I guess the reason is clear. We usually split things into specified parts which are not contradictory. A special thing can be small and medium, as one group, and large, as the other group. But it cannot be small and large at the same time. The point is that you have a sequence in your data. If there was no such thing you could have different combinations of attribute values. Suppose you have a set of attribute values for a fruit. It can be apple, pineapple and watermelon. Due to the fact that there is no ordinal, you can have all possible combination for binary splits; in the previous case, you can not because your binary split somehow violates the logical sequence.






          share|improve this answer









          $endgroup$












          • $begingroup$
            To me is useless, since for example a T-shirt factory can decide to print red tshirts of size Small and Large and blue tshirts of sizes medium and extralarge. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?
            $endgroup$
            – Koinos
            Aug 1 '18 at 12:06











          • $begingroup$
            Well@Koinos, feature construction is one of the important tasks of the modeler. It is up to you to decide whether to represent a categorical veriable as ordered or unordered.
            $endgroup$
            – Michael M
            Aug 1 '18 at 12:13










          • $begingroup$
            I don't grab the advantages of maintaining the order of an attribute splits...
            $endgroup$
            – Koinos
            Aug 1 '18 at 12:23










          • $begingroup$
            @Koinos in the example that you have provided, actually you are not preserving the order and your ordinal attribute is actually more nominal. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?. Well, this is not true entirely due to the fact that we have the data and we can have assumptions about the distribution of data. Moreover, there are approaches to findout it's better to have binary or multiway splits.
            $endgroup$
            – Vaalizaadeh
            Aug 1 '18 at 12:41










          • $begingroup$
            For binary, depnding on your information criterion, such as Gini, Information Gain or maybe Gain Ratio, you as the ML practitioner have to find out the best part to split. But one of the things that can get complicated is that ordinal features may be used multiple times for a path from the root to a leaf. In that way, if you don't preseverve the order, it can get so much complicated.
            $endgroup$
            – Vaalizaadeh
            Aug 1 '18 at 12:41


















          0












          $begingroup$

          I'd say the distinct handling of the ordered and unordered factor in decision trees is more convention and
          implementation detail than a necessity.



          But it is also an important optimization feature. See the documentation of the rpart here




          We have said that for a categorical predictor with $m$ levels, all $2^(m-1)$ different possible splits are tested..




          and




          Luckily, for any ordered outcome there is a computational shortcut that allows the program to find the best split using only $m-1$ comparisons.




          As you see, the ordered factor may be processed much effectively.



          My advice therefore - as a part of the feature ingeneering decide whether to use a factor ordered or unordered:



          Use ordered factor only if it is highly correlated with the output variable, otherwise fall back to an unordered factor



          Bellow is a simple example, how can a scattered output variable with an ordered factor as a feature fool the decision treee to be very deep and ineffective.



          > df
          X Y
          1 1 0
          2 2 1
          3 3 0
          4 4 1
          > str(df)
          'data.frame': 4 obs. of 2 variables:
          $ X: Ord.factor w/ 4 levels "1"<"2"<"3"<"4": 1 2 3 4
          $ Y: num 0 1 0 1


          Notice that the output variable $Y$ is highly uncorrelated with the ordered factor.



          > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1)) 
          > print(fit)
          n= 4

          node), split, n, loss, yval, (yprob)
          * denotes terminal node

          1) root 4 2 0 (0.50000000 0.50000000)
          2) X=1 1 0 0 (1.00000000 0.00000000) *
          3) X=2,3,4 3 1 1 (0.33333333 0.66666667)
          6) X=3,4 2 1 0 (0.50000000 0.50000000)
          12) X=1,2,3 1 0 0 (1.00000000 0.00000000) *
          13) X=4 1 0 1 (0.00000000 1.00000000) *
          7) X=1,2 1 0 1 (0.00000000 1.00000000) *


          Which leads to a deep (and unscalable) decision tree.



          enter image description here



          Making the factor unordered results in the optimal decision tree.



          > df
          X Y
          1 1 0
          2 2 1
          3 3 0
          4 4 1
          > str(df)
          'data.frame': 4 obs. of 2 variables:
          $ X: Factor w/ 4 levels "1","2","3","4": 1 2 3 4
          $ Y: num 0 1 0 1
          >

          > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1))
          > print(fit)
          n= 4

          node), split, n, loss, yval, (yprob)
          * denotes terminal node

          1) root 4 2 0 (0.50000000 0.50000000)
          2) X=1,3 2 0 0 (1.00000000 0.00000000) *
          3) X=2,4 2 0 1 (0.00000000 1.00000000) *


          enter image description here






          share|improve this answer











          $endgroup$













            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "557"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f36303%2fordinal-attributes-in-a-decision-tree%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0












            $begingroup$

            I guess the reason is clear. We usually split things into specified parts which are not contradictory. A special thing can be small and medium, as one group, and large, as the other group. But it cannot be small and large at the same time. The point is that you have a sequence in your data. If there was no such thing you could have different combinations of attribute values. Suppose you have a set of attribute values for a fruit. It can be apple, pineapple and watermelon. Due to the fact that there is no ordinal, you can have all possible combination for binary splits; in the previous case, you can not because your binary split somehow violates the logical sequence.






            share|improve this answer









            $endgroup$












            • $begingroup$
              To me is useless, since for example a T-shirt factory can decide to print red tshirts of size Small and Large and blue tshirts of sizes medium and extralarge. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:06











            • $begingroup$
              Well@Koinos, feature construction is one of the important tasks of the modeler. It is up to you to decide whether to represent a categorical veriable as ordered or unordered.
              $endgroup$
              – Michael M
              Aug 1 '18 at 12:13










            • $begingroup$
              I don't grab the advantages of maintaining the order of an attribute splits...
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:23










            • $begingroup$
              @Koinos in the example that you have provided, actually you are not preserving the order and your ordinal attribute is actually more nominal. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?. Well, this is not true entirely due to the fact that we have the data and we can have assumptions about the distribution of data. Moreover, there are approaches to findout it's better to have binary or multiway splits.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41










            • $begingroup$
              For binary, depnding on your information criterion, such as Gini, Information Gain or maybe Gain Ratio, you as the ML practitioner have to find out the best part to split. But one of the things that can get complicated is that ordinal features may be used multiple times for a path from the root to a leaf. In that way, if you don't preseverve the order, it can get so much complicated.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41















            0












            $begingroup$

            I guess the reason is clear. We usually split things into specified parts which are not contradictory. A special thing can be small and medium, as one group, and large, as the other group. But it cannot be small and large at the same time. The point is that you have a sequence in your data. If there was no such thing you could have different combinations of attribute values. Suppose you have a set of attribute values for a fruit. It can be apple, pineapple and watermelon. Due to the fact that there is no ordinal, you can have all possible combination for binary splits; in the previous case, you can not because your binary split somehow violates the logical sequence.






            share|improve this answer









            $endgroup$












            • $begingroup$
              To me is useless, since for example a T-shirt factory can decide to print red tshirts of size Small and Large and blue tshirts of sizes medium and extralarge. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:06











            • $begingroup$
              Well@Koinos, feature construction is one of the important tasks of the modeler. It is up to you to decide whether to represent a categorical veriable as ordered or unordered.
              $endgroup$
              – Michael M
              Aug 1 '18 at 12:13










            • $begingroup$
              I don't grab the advantages of maintaining the order of an attribute splits...
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:23










            • $begingroup$
              @Koinos in the example that you have provided, actually you are not preserving the order and your ordinal attribute is actually more nominal. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?. Well, this is not true entirely due to the fact that we have the data and we can have assumptions about the distribution of data. Moreover, there are approaches to findout it's better to have binary or multiway splits.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41










            • $begingroup$
              For binary, depnding on your information criterion, such as Gini, Information Gain or maybe Gain Ratio, you as the ML practitioner have to find out the best part to split. But one of the things that can get complicated is that ordinal features may be used multiple times for a path from the root to a leaf. In that way, if you don't preseverve the order, it can get so much complicated.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41













            0












            0








            0





            $begingroup$

            I guess the reason is clear. We usually split things into specified parts which are not contradictory. A special thing can be small and medium, as one group, and large, as the other group. But it cannot be small and large at the same time. The point is that you have a sequence in your data. If there was no such thing you could have different combinations of attribute values. Suppose you have a set of attribute values for a fruit. It can be apple, pineapple and watermelon. Due to the fact that there is no ordinal, you can have all possible combination for binary splits; in the previous case, you can not because your binary split somehow violates the logical sequence.






            share|improve this answer









            $endgroup$



            I guess the reason is clear. We usually split things into specified parts which are not contradictory. A special thing can be small and medium, as one group, and large, as the other group. But it cannot be small and large at the same time. The point is that you have a sequence in your data. If there was no such thing you could have different combinations of attribute values. Suppose you have a set of attribute values for a fruit. It can be apple, pineapple and watermelon. Due to the fact that there is no ordinal, you can have all possible combination for binary splits; in the previous case, you can not because your binary split somehow violates the logical sequence.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 1 '18 at 11:39









            VaalizaadehVaalizaadeh

            7,59562264




            7,59562264











            • $begingroup$
              To me is useless, since for example a T-shirt factory can decide to print red tshirts of size Small and Large and blue tshirts of sizes medium and extralarge. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:06











            • $begingroup$
              Well@Koinos, feature construction is one of the important tasks of the modeler. It is up to you to decide whether to represent a categorical veriable as ordered or unordered.
              $endgroup$
              – Michael M
              Aug 1 '18 at 12:13










            • $begingroup$
              I don't grab the advantages of maintaining the order of an attribute splits...
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:23










            • $begingroup$
              @Koinos in the example that you have provided, actually you are not preserving the order and your ordinal attribute is actually more nominal. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?. Well, this is not true entirely due to the fact that we have the data and we can have assumptions about the distribution of data. Moreover, there are approaches to findout it's better to have binary or multiway splits.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41










            • $begingroup$
              For binary, depnding on your information criterion, such as Gini, Information Gain or maybe Gain Ratio, you as the ML practitioner have to find out the best part to split. But one of the things that can get complicated is that ordinal features may be used multiple times for a path from the root to a leaf. In that way, if you don't preseverve the order, it can get so much complicated.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41
















            • $begingroup$
              To me is useless, since for example a T-shirt factory can decide to print red tshirts of size Small and Large and blue tshirts of sizes medium and extralarge. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:06











            • $begingroup$
              Well@Koinos, feature construction is one of the important tasks of the modeler. It is up to you to decide whether to represent a categorical veriable as ordered or unordered.
              $endgroup$
              – Michael M
              Aug 1 '18 at 12:13










            • $begingroup$
              I don't grab the advantages of maintaining the order of an attribute splits...
              $endgroup$
              – Koinos
              Aug 1 '18 at 12:23










            • $begingroup$
              @Koinos in the example that you have provided, actually you are not preserving the order and your ordinal attribute is actually more nominal. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?. Well, this is not true entirely due to the fact that we have the data and we can have assumptions about the distribution of data. Moreover, there are approaches to findout it's better to have binary or multiway splits.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41










            • $begingroup$
              For binary, depnding on your information criterion, such as Gini, Information Gain or maybe Gain Ratio, you as the ML practitioner have to find out the best part to split. But one of the things that can get complicated is that ordinal features may be used multiple times for a path from the root to a leaf. In that way, if you don't preseverve the order, it can get so much complicated.
              $endgroup$
              – Vaalizaadeh
              Aug 1 '18 at 12:41















            $begingroup$
            To me is useless, since for example a T-shirt factory can decide to print red tshirts of size Small and Large and blue tshirts of sizes medium and extralarge. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?
            $endgroup$
            – Koinos
            Aug 1 '18 at 12:06





            $begingroup$
            To me is useless, since for example a T-shirt factory can decide to print red tshirts of size Small and Large and blue tshirts of sizes medium and extralarge. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?
            $endgroup$
            – Koinos
            Aug 1 '18 at 12:06













            $begingroup$
            Well@Koinos, feature construction is one of the important tasks of the modeler. It is up to you to decide whether to represent a categorical veriable as ordered or unordered.
            $endgroup$
            – Michael M
            Aug 1 '18 at 12:13




            $begingroup$
            Well@Koinos, feature construction is one of the important tasks of the modeler. It is up to you to decide whether to represent a categorical veriable as ordered or unordered.
            $endgroup$
            – Michael M
            Aug 1 '18 at 12:13












            $begingroup$
            I don't grab the advantages of maintaining the order of an attribute splits...
            $endgroup$
            – Koinos
            Aug 1 '18 at 12:23




            $begingroup$
            I don't grab the advantages of maintaining the order of an attribute splits...
            $endgroup$
            – Koinos
            Aug 1 '18 at 12:23












            $begingroup$
            @Koinos in the example that you have provided, actually you are not preserving the order and your ordinal attribute is actually more nominal. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?. Well, this is not true entirely due to the fact that we have the data and we can have assumptions about the distribution of data. Moreover, there are approaches to findout it's better to have binary or multiway splits.
            $endgroup$
            – Vaalizaadeh
            Aug 1 '18 at 12:41




            $begingroup$
            @Koinos in the example that you have provided, actually you are not preserving the order and your ordinal attribute is actually more nominal. Since we don't know the model that generates the data how can we infer that it's "better" to preserve the order in the splits of a ordinal attribute ?. Well, this is not true entirely due to the fact that we have the data and we can have assumptions about the distribution of data. Moreover, there are approaches to findout it's better to have binary or multiway splits.
            $endgroup$
            – Vaalizaadeh
            Aug 1 '18 at 12:41












            $begingroup$
            For binary, depnding on your information criterion, such as Gini, Information Gain or maybe Gain Ratio, you as the ML practitioner have to find out the best part to split. But one of the things that can get complicated is that ordinal features may be used multiple times for a path from the root to a leaf. In that way, if you don't preseverve the order, it can get so much complicated.
            $endgroup$
            – Vaalizaadeh
            Aug 1 '18 at 12:41




            $begingroup$
            For binary, depnding on your information criterion, such as Gini, Information Gain or maybe Gain Ratio, you as the ML practitioner have to find out the best part to split. But one of the things that can get complicated is that ordinal features may be used multiple times for a path from the root to a leaf. In that way, if you don't preseverve the order, it can get so much complicated.
            $endgroup$
            – Vaalizaadeh
            Aug 1 '18 at 12:41











            0












            $begingroup$

            I'd say the distinct handling of the ordered and unordered factor in decision trees is more convention and
            implementation detail than a necessity.



            But it is also an important optimization feature. See the documentation of the rpart here




            We have said that for a categorical predictor with $m$ levels, all $2^(m-1)$ different possible splits are tested..




            and




            Luckily, for any ordered outcome there is a computational shortcut that allows the program to find the best split using only $m-1$ comparisons.




            As you see, the ordered factor may be processed much effectively.



            My advice therefore - as a part of the feature ingeneering decide whether to use a factor ordered or unordered:



            Use ordered factor only if it is highly correlated with the output variable, otherwise fall back to an unordered factor



            Bellow is a simple example, how can a scattered output variable with an ordered factor as a feature fool the decision treee to be very deep and ineffective.



            > df
            X Y
            1 1 0
            2 2 1
            3 3 0
            4 4 1
            > str(df)
            'data.frame': 4 obs. of 2 variables:
            $ X: Ord.factor w/ 4 levels "1"<"2"<"3"<"4": 1 2 3 4
            $ Y: num 0 1 0 1


            Notice that the output variable $Y$ is highly uncorrelated with the ordered factor.



            > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1)) 
            > print(fit)
            n= 4

            node), split, n, loss, yval, (yprob)
            * denotes terminal node

            1) root 4 2 0 (0.50000000 0.50000000)
            2) X=1 1 0 0 (1.00000000 0.00000000) *
            3) X=2,3,4 3 1 1 (0.33333333 0.66666667)
            6) X=3,4 2 1 0 (0.50000000 0.50000000)
            12) X=1,2,3 1 0 0 (1.00000000 0.00000000) *
            13) X=4 1 0 1 (0.00000000 1.00000000) *
            7) X=1,2 1 0 1 (0.00000000 1.00000000) *


            Which leads to a deep (and unscalable) decision tree.



            enter image description here



            Making the factor unordered results in the optimal decision tree.



            > df
            X Y
            1 1 0
            2 2 1
            3 3 0
            4 4 1
            > str(df)
            'data.frame': 4 obs. of 2 variables:
            $ X: Factor w/ 4 levels "1","2","3","4": 1 2 3 4
            $ Y: num 0 1 0 1
            >

            > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1))
            > print(fit)
            n= 4

            node), split, n, loss, yval, (yprob)
            * denotes terminal node

            1) root 4 2 0 (0.50000000 0.50000000)
            2) X=1,3 2 0 0 (1.00000000 0.00000000) *
            3) X=2,4 2 0 1 (0.00000000 1.00000000) *


            enter image description here






            share|improve this answer











            $endgroup$

















              0












              $begingroup$

              I'd say the distinct handling of the ordered and unordered factor in decision trees is more convention and
              implementation detail than a necessity.



              But it is also an important optimization feature. See the documentation of the rpart here




              We have said that for a categorical predictor with $m$ levels, all $2^(m-1)$ different possible splits are tested..




              and




              Luckily, for any ordered outcome there is a computational shortcut that allows the program to find the best split using only $m-1$ comparisons.




              As you see, the ordered factor may be processed much effectively.



              My advice therefore - as a part of the feature ingeneering decide whether to use a factor ordered or unordered:



              Use ordered factor only if it is highly correlated with the output variable, otherwise fall back to an unordered factor



              Bellow is a simple example, how can a scattered output variable with an ordered factor as a feature fool the decision treee to be very deep and ineffective.



              > df
              X Y
              1 1 0
              2 2 1
              3 3 0
              4 4 1
              > str(df)
              'data.frame': 4 obs. of 2 variables:
              $ X: Ord.factor w/ 4 levels "1"<"2"<"3"<"4": 1 2 3 4
              $ Y: num 0 1 0 1


              Notice that the output variable $Y$ is highly uncorrelated with the ordered factor.



              > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1)) 
              > print(fit)
              n= 4

              node), split, n, loss, yval, (yprob)
              * denotes terminal node

              1) root 4 2 0 (0.50000000 0.50000000)
              2) X=1 1 0 0 (1.00000000 0.00000000) *
              3) X=2,3,4 3 1 1 (0.33333333 0.66666667)
              6) X=3,4 2 1 0 (0.50000000 0.50000000)
              12) X=1,2,3 1 0 0 (1.00000000 0.00000000) *
              13) X=4 1 0 1 (0.00000000 1.00000000) *
              7) X=1,2 1 0 1 (0.00000000 1.00000000) *


              Which leads to a deep (and unscalable) decision tree.



              enter image description here



              Making the factor unordered results in the optimal decision tree.



              > df
              X Y
              1 1 0
              2 2 1
              3 3 0
              4 4 1
              > str(df)
              'data.frame': 4 obs. of 2 variables:
              $ X: Factor w/ 4 levels "1","2","3","4": 1 2 3 4
              $ Y: num 0 1 0 1
              >

              > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1))
              > print(fit)
              n= 4

              node), split, n, loss, yval, (yprob)
              * denotes terminal node

              1) root 4 2 0 (0.50000000 0.50000000)
              2) X=1,3 2 0 0 (1.00000000 0.00000000) *
              3) X=2,4 2 0 1 (0.00000000 1.00000000) *


              enter image description here






              share|improve this answer











              $endgroup$















                0












                0








                0





                $begingroup$

                I'd say the distinct handling of the ordered and unordered factor in decision trees is more convention and
                implementation detail than a necessity.



                But it is also an important optimization feature. See the documentation of the rpart here




                We have said that for a categorical predictor with $m$ levels, all $2^(m-1)$ different possible splits are tested..




                and




                Luckily, for any ordered outcome there is a computational shortcut that allows the program to find the best split using only $m-1$ comparisons.




                As you see, the ordered factor may be processed much effectively.



                My advice therefore - as a part of the feature ingeneering decide whether to use a factor ordered or unordered:



                Use ordered factor only if it is highly correlated with the output variable, otherwise fall back to an unordered factor



                Bellow is a simple example, how can a scattered output variable with an ordered factor as a feature fool the decision treee to be very deep and ineffective.



                > df
                X Y
                1 1 0
                2 2 1
                3 3 0
                4 4 1
                > str(df)
                'data.frame': 4 obs. of 2 variables:
                $ X: Ord.factor w/ 4 levels "1"<"2"<"3"<"4": 1 2 3 4
                $ Y: num 0 1 0 1


                Notice that the output variable $Y$ is highly uncorrelated with the ordered factor.



                > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1)) 
                > print(fit)
                n= 4

                node), split, n, loss, yval, (yprob)
                * denotes terminal node

                1) root 4 2 0 (0.50000000 0.50000000)
                2) X=1 1 0 0 (1.00000000 0.00000000) *
                3) X=2,3,4 3 1 1 (0.33333333 0.66666667)
                6) X=3,4 2 1 0 (0.50000000 0.50000000)
                12) X=1,2,3 1 0 0 (1.00000000 0.00000000) *
                13) X=4 1 0 1 (0.00000000 1.00000000) *
                7) X=1,2 1 0 1 (0.00000000 1.00000000) *


                Which leads to a deep (and unscalable) decision tree.



                enter image description here



                Making the factor unordered results in the optimal decision tree.



                > df
                X Y
                1 1 0
                2 2 1
                3 3 0
                4 4 1
                > str(df)
                'data.frame': 4 obs. of 2 variables:
                $ X: Factor w/ 4 levels "1","2","3","4": 1 2 3 4
                $ Y: num 0 1 0 1
                >

                > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1))
                > print(fit)
                n= 4

                node), split, n, loss, yval, (yprob)
                * denotes terminal node

                1) root 4 2 0 (0.50000000 0.50000000)
                2) X=1,3 2 0 0 (1.00000000 0.00000000) *
                3) X=2,4 2 0 1 (0.00000000 1.00000000) *


                enter image description here






                share|improve this answer











                $endgroup$



                I'd say the distinct handling of the ordered and unordered factor in decision trees is more convention and
                implementation detail than a necessity.



                But it is also an important optimization feature. See the documentation of the rpart here




                We have said that for a categorical predictor with $m$ levels, all $2^(m-1)$ different possible splits are tested..




                and




                Luckily, for any ordered outcome there is a computational shortcut that allows the program to find the best split using only $m-1$ comparisons.




                As you see, the ordered factor may be processed much effectively.



                My advice therefore - as a part of the feature ingeneering decide whether to use a factor ordered or unordered:



                Use ordered factor only if it is highly correlated with the output variable, otherwise fall back to an unordered factor



                Bellow is a simple example, how can a scattered output variable with an ordered factor as a feature fool the decision treee to be very deep and ineffective.



                > df
                X Y
                1 1 0
                2 2 1
                3 3 0
                4 4 1
                > str(df)
                'data.frame': 4 obs. of 2 variables:
                $ X: Ord.factor w/ 4 levels "1"<"2"<"3"<"4": 1 2 3 4
                $ Y: num 0 1 0 1


                Notice that the output variable $Y$ is highly uncorrelated with the ordered factor.



                > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1)) 
                > print(fit)
                n= 4

                node), split, n, loss, yval, (yprob)
                * denotes terminal node

                1) root 4 2 0 (0.50000000 0.50000000)
                2) X=1 1 0 0 (1.00000000 0.00000000) *
                3) X=2,3,4 3 1 1 (0.33333333 0.66666667)
                6) X=3,4 2 1 0 (0.50000000 0.50000000)
                12) X=1,2,3 1 0 0 (1.00000000 0.00000000) *
                13) X=4 1 0 1 (0.00000000 1.00000000) *
                7) X=1,2 1 0 1 (0.00000000 1.00000000) *


                Which leads to a deep (and unscalable) decision tree.



                enter image description here



                Making the factor unordered results in the optimal decision tree.



                > df
                X Y
                1 1 0
                2 2 1
                3 3 0
                4 4 1
                > str(df)
                'data.frame': 4 obs. of 2 variables:
                $ X: Factor w/ 4 levels "1","2","3","4": 1 2 3 4
                $ Y: num 0 1 0 1
                >

                > fit <- rpart(Y ~ X, method="class", data = df, control=rpart.control(minsplit = 1))
                > print(fit)
                n= 4

                node), split, n, loss, yval, (yprob)
                * denotes terminal node

                1) root 4 2 0 (0.50000000 0.50000000)
                2) X=1,3 2 0 0 (1.00000000 0.00000000) *
                3) X=2,4 2 0 1 (0.00000000 1.00000000) *


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 19 '18 at 8:31

























                answered Aug 18 '18 at 13:41









                Marmite BomberMarmite Bomber

                9531611




                9531611



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f36303%2fordinal-attributes-in-a-decision-tree%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Ружовы пелікан Змест Знешні выгляд | Пашырэнне | Асаблівасці біялогіі | Літаратура | НавігацыяДагледжаная версіяправерана1 зменаДагледжаная версіяправерана1 змена/ 22697590 Сістэматыкана ВіківідахВыявына Вікісховішчы174693363011049382

                    ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)2019 Community Moderator ElectionError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)Error 'Expected 2D array, got 1D array instead:'ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Steps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)

                    Illegal assignment from SObject to ContactFetching String, Id from Map - Illegal Assignment Id to Field / ObjectError: Compile Error: Illegal assignment from String to BooleanError: List has no rows for assignment to SObjectError on Test Class - System.QueryException: List has no rows for assignment to SObjectRemote action problemDML requires SObject or SObject list type error“Illegal assignment from List to List”Test Class Fail: Batch Class: System.QueryException: List has no rows for assignment to SObjectMapping to a user'List has no rows for assignment to SObject' Mystery