(self, data)
return best_res
Select the attribute for the next split.

        Returns
        -------
        tuple with an instance of Node and a numpy array indicating
        the branch index for each data instance, or -1 if data instance
        is dropped
Select the attribute for the next split.
Select the attribute for the next split .
def _select_attr(self, data):
        """Select the attribute for the next split.

        Returns
        -------
        tuple with an instance of Node and a numpy array indicating
        the branch index for each data instance, or -1 if data instance
        is dropped
        """
        # Prevent false warnings by pylint
        attr = attr_no = None
        REJECT_ATTRIBUTE = 0, None, None, 0

        def _score_disc():
            n_values = len(attr.values)
            score = _tree_scorers.compute_grouped_MSE(
                col_x, col_y, n_values, self.min_samples_leaf)
            # The score is already adjusted for missing attribute values, so
            # we don't do it here
            if score == 0:
                return REJECT_ATTRIBUTE
            branches = col_x.flatten()
            branches[np.isnan(branches)] = -1
            return score, DiscreteNode(attr, attr_no, None), branches, n_values

        def _score_disc_bin():
            n_values = len(attr.values)
            if n_values == 2:
                return _score_disc()
            score, mapping = _tree_scorers.find_binarization_MSE(
                col_x, col_y, n_values, self.min_samples_leaf)
            # The score is already adjusted for missing attribute values, so
            # we don't do it here
            if score == 0:
                return REJECT_ATTRIBUTE
            mapping, branches = MappedDiscreteNode.branches_from_mapping(
                col_x, mapping, len(attr.values))
            node = MappedDiscreteNode(attr, attr_no, mapping, None)
            return score, node, branches, 2

        def _score_cont():
            """Scoring for numeric attributes"""
            nans = np.sum(np.isnan(col_x))
            non_nans = len(col_x) - nans
            arginds = np.argsort(col_x)[:non_nans]
            score, cut = _tree_scorers.find_threshold_MSE(
                col_x, col_y, arginds, self.min_samples_leaf)
            if score == 0:
                return  REJECT_ATTRIBUTE
            score *= non_nans / len(col_x)
            branches = np.full(len(col_x), -1, dtype=int)
            mask = ~np.isnan(col_x)
            branches[mask] = (col_x[mask] > cut).astype(int)
            node = NumericNode(attr, attr_no, cut, None)
            return score, node, branches, 2

        #######################################
        # The real _select_attr starts here
        is_sparse = sp.issparse(data.X)
        domain = data.domain
        col_y = data.Y
        best_score, *best_res = REJECT_ATTRIBUTE
        best_res = [Node(None, 0, None), ] + best_res[1:]
        disc_scorer = _score_disc_bin if self.binarize else _score_disc
        for attr_no, attr in enumerate(domain.attributes):
            col_x = data[:, attr_no].X
            if is_sparse:
                col_x = col_x.toarray()
            col_x = col_x.reshape((len(data),))
            sc, *res = disc_scorer() if attr.is_discrete else _score_cont()
            if res[0] is not None and sc > best_score:
                best_score, best_res = sc, res
        return best_res
def _select_attr ( self , data ) : # Prevent false warnings by pylint attr = attr_no = None REJECT_ATTRIBUTE = 0 , None , None , 0 def _score_disc ( ) : n_values = len ( attr . values ) score = _tree_scorers . compute_grouped_MSE ( col_x , col_y , n_values , self . min_samples_leaf ) # The score is already adjusted for missing attribute values, so # we don't do it here if score == 0 : return REJECT_ATTRIBUTE branches = col_x . flatten ( ) branches [ np . isnan ( branches ) ] = - 1 return score , DiscreteNode ( attr , attr_no , None ) , branches , n_values def _score_disc_bin ( ) : n_values = len ( attr . values ) if n_values == 2 : return _score_disc ( ) score , mapping = _tree_scorers . find_binarization_MSE ( col_x , col_y , n_values , self . min_samples_leaf ) # The score is already adjusted for missing attribute values, so # we don't do it here if score == 0 : return REJECT_ATTRIBUTE mapping , branches = MappedDiscreteNode . branches_from_mapping ( col_x , mapping , len ( attr . values ) ) node = MappedDiscreteNode ( attr , attr_no , mapping , None ) return score , node , branches , 2 def _score_cont ( ) : """Scoring for numeric attributes""" nans = np . sum ( np . isnan ( col_x ) ) non_nans = len ( col_x ) - nans arginds = np . argsort ( col_x ) [ : non_nans ] score , cut = _tree_scorers . find_threshold_MSE ( col_x , col_y , arginds , self . min_samples_leaf ) if score == 0 : return REJECT_ATTRIBUTE score *= non_nans / len ( col_x ) branches = np . full ( len ( col_x ) , - 1 , dtype = int ) mask = ~ np . isnan ( col_x ) branches [ mask ] = ( col_x [ mask ] > cut ) . astype ( int ) node = NumericNode ( attr , attr_no , cut , None ) return score , node , branches , 2 ####################################### # The real _select_attr starts here is_sparse = sp . issparse ( data . X ) domain = data . domain col_y = data . Y best_score , * best_res = REJECT_ATTRIBUTE best_res = [ Node ( None , 0 , None ) , ] + best_res [ 1 : ] disc_scorer = _score_disc_bin if self . binarize else _score_disc for attr_no , attr in enumerate ( domain . attributes ) : col_x = data [ : , attr_no ] . X if is_sparse : col_x = col_x . toarray ( ) col_x = col_x . reshape ( ( len ( data ) , ) ) sc , * res = disc_scorer ( ) if attr . is_discrete else _score_cont ( ) if res [ 0 ] is not None and sc > best_score : best_score , best_res = sc , res return best_res