[mlpack-git] master: Don't overwrite majorityClass. (22c32fb)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:43:44 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125

>---------------------------------------------------------------

commit 22c32fb7d9271a51970d5faa88f3d975faaa027d
Author: ryan <ryan at ratml.org>
Date:   Thu Oct 1 20:04:54 2015 -0400

    Don't overwrite majorityClass.


>---------------------------------------------------------------

22c32fb7d9271a51970d5faa88f3d975faaa027d
 .../methods/hoeffding_trees/hoeffding_split_impl.hpp | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp
index cdd8ff9..8a9ca73 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp
@@ -105,6 +105,12 @@ void HoeffdingSplit<
       else if (datasetInfo->Type(i) == data::Datatype::numeric)
         numericSplits[numericIndex++].Train(point[i], label);
     }
+
+    // Grab majority class from splits.
+    if (categoricalSplits.size() > 0)
+      majorityClass = categoricalSplits[0].MajorityClass();
+    else
+      majorityClass = numericSplits[0].MajorityClass();
   }
   else
   {
@@ -197,17 +203,6 @@ size_t HoeffdingSplit<
     CategoricalSplitType
 >::MajorityClass() const
 {
-  // If the node is not split yet, we have to grab the majority class from any
-  // of the structures figuring out what to split on.
-  if (splitDimension == size_t(-1))
-  {
-    // Grab majority class from splits.
-    if (categoricalSplits.size() > 0)
-      majorityClass = categoricalSplits[0].MajorityClass();
-    else
-      majorityClass = numericSplits[0].MajorityClass();
-  }
-
   return majorityClass;
 }
 
@@ -322,6 +317,7 @@ void HoeffdingSplit<
   ar & CreateNVP(dimensionMappings, "dimensionMappings");
   ar & CreateNVP(ownsMappings, "ownsMappings");
   ar & CreateNVP(datasetInfo, "datasetInfo");
+  ar & CreateNVP(majorityClass, "majorityClass");
 
   // Depending on whether or not we have split yet, we may need to save
   // different things.
@@ -381,7 +377,6 @@ void HoeffdingSplit<
     if (Archive::is_loading::value)
     {
       // Clear things we don't need.
-      majorityClass = 0;
       categoricalSplit = typename CategoricalSplitType::SplitInfo(numClasses);
       numericSplit = typename NumericSplitType::SplitInfo();
     }
@@ -392,7 +387,6 @@ void HoeffdingSplit<
     // split.
     ar & CreateNVP(categoricalSplit, "categoricalSplit");
     ar & CreateNVP(numericSplit, "numericSplit");
-    ar & CreateNVP(majorityClass, "majorityClass");
 
     if (Archive::is_loading::value)
     {



More information about the mlpack-git mailing list