SHARE
TWEET

Untitled

a guest Feb 14th, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function buildTree(array $criteria = [])
  2. {
  3.     $treeNode = new TreeNode();
  4.     $checkClass = $this->isBelongToOneClass($criteria);
  5.     if ($checkClass['return']) {
  6.         $treeNode->setAttribute($this->targetAttribute);
  7.         $treeNode->addChild('result', $checkClass['class']);
  8.         $treeNode->setIsLeaf(true);
  9.  
  10.         return $treeNode;
  11.     }
  12.     $splitCriterion = $this->calculateSplitCriterion($criteria);
  13.     $bestAttrName = $this->getBiggestArrayAttribute($splitCriterion);
  14.     $bestAttrValues = $this->getAttributeValues($bestAttrName);
  15.     $treeNode->setAttribute($bestAttrName);
  16.     unset($splitCriterion[$bestAttrName]);    
  17.     foreach ($bestAttrValues as $value) {
  18.         $criteria[$bestAttrName] = $value;
  19.         $targetCount = $this->countTargetByCriteria($criteria);
  20.         $treeNode->addClassesCount($value, $targetCount);
  21.         if (array_sum($targetCount) == 0) {
  22.             $targetCount2 = $this->countTargetByCriteria([$bestAttrName => $value]);
  23.             $biggestClass = $this->getBiggestArrayAttribute($targetCount2);
  24.             $child = new TreeNode();
  25.             $child->setParent($treeNode);
  26.             $child->setAttribute($this->targetAttribute);
  27.             $child->addChild('result', $biggestClass);
  28.             $child->setIsLeaf(true);
  29.             $treeNode->addChild($value, $child);
  30.         } elseif (!empty($splitCriterion)) {
  31.             $child = $this->buildTree($criteria);
  32.             $child->setParent($treeNode);
  33.             $treeNode->addChild($value, $child);
  34.         } else {
  35.             $classProb = $this->calculateClassProbability($criteria);
  36.             $biggestClass = $this->getBiggestArrayAttribute($classProb);
  37.             $child = new TreeNode();
  38.             $child->setParent($treeNode);
  39.             $child->setAttribute($this->targetAttribute);
  40.             $child->addChild('result', $biggestClass);
  41.             $child->setIsLeaf(true);
  42.             $treeNode->addChild($value, $child);
  43.         }
  44.     }
  45.  
  46.     return $treeNode;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top