| 60 | |
| 61 | class RandomForestClassifier(RandomForest): |
| 62 | def __init__( |
| 63 | self, |
| 64 | n_estimators=10, |
| 65 | max_features=None, |
| 66 | min_samples_split=10, |
| 67 | max_depth=None, |
| 68 | criterion="entropy", |
| 69 | ): |
| 70 | super(RandomForestClassifier, self).__init__( |
| 71 | n_estimators=n_estimators, |
| 72 | max_features=max_features, |
| 73 | min_samples_split=min_samples_split, |
| 74 | max_depth=max_depth, |
| 75 | criterion=criterion, |
| 76 | ) |
| 77 | |
| 78 | if criterion == "entropy": |
| 79 | self.criterion = information_gain |
| 80 | else: |
| 81 | raise ValueError() |
| 82 | |
| 83 | # Initialize empty trees |
| 84 | for _ in range(self.n_estimators): |
| 85 | self.trees.append(Tree(criterion=self.criterion)) |
| 86 | |
| 87 | def _predict(self, X=None): |
| 88 | y_shape = np.unique(self.y).shape[0] |