private TreeNode createDecisionNode(int bestFeatureIdx, DataSet dataset){
        // calculate the mean. 
        double mean = 0;
        int dataSize = dataset.getNumOfInstance();
        for (int i = 0; i < dataSize; i++){
            double[] featureVector = dataset.getInstance(i).getFeatureVector();
            mean += featureVector[bestFeatureIdx]/dataSize;
        }
        
        List<Instance> leftDataSet = new ArrayList<Instance>();
        List<Instance> rightDataSet = new ArrayList<Instance>();
        // divide the datasets into two subset, based on the mean value. 
        for (int i = 0; i < dataSize; i++){
            // smaller one goes to left. 
            if ((dataset.getInstance(i).getFeatureVector())[bestFeatureIdx] < mean)
                leftDataSet.add(dataset.getInstance(i));
            else
                rightDataSet.add(dataset.getInstance(i));
        }
          
        // create new decision node, and set the left child and right child. 
        TreeNode node = new DecisionNode(bestFeatureIdx, mean);
        if (leftDataSet.size() > 0){
            ((DecisionNode)node).setLeftChild(build(new DataSet(leftDataSet)));
        } else{
            // create leaf node, with majority distribution. 
            TreeNode leafNode = new LeafNode(numLabels, dataset.getLabels());
            ((DecisionNode)node).setLeftChild(leafNode);
        }
            
        if (rightDataSet.size() > 0){
            ((DecisionNode)node).setRightChild(build(new DataSet(rightDataSet)));
        } else{
            // create leaf node, with majority distribution. 
            TreeNode leafNode = new LeafNode(numLabels, dataset.getLabels());
            ((DecisionNode)node).setRightChild(leafNode);
        }

        return node;
    }