Machine-Learning-From-Scratch icon indicating copy to clipboard operation
Machine-Learning-From-Scratch copied to clipboard

Code Outdated in DecisionTree.py

Open ntvviktor opened this issue 2 years ago • 1 comments

Some places need to use iloc to slice instead of default accessors.

def _best_split(self, X, y, feat_idxs):
        best_gain = -1
        split_idx, split_threshold = None, None

        for feat_idx in feat_idxs:
            # iloc instead
            X_column = X.iloc[:, feat_idx]
            thresholds = np.unique(X_column)

            for thr in thresholds:
                # calculate the information gain
                gain = self._information_gain(y, X_column, thr)

                if gain > best_gain:
                    best_gain = gain
                    split_idx = feat_idx
                    split_threshold = thr
        return split_idx, split_threshold

ntvviktor avatar Jan 21 '23 15:01 ntvviktor

X is numpy array and numpy array does not have the attribute "iloc"

ShubhamZoro avatar Jul 20 '23 07:07 ShubhamZoro