Skip to content

Commit

Permalink
feat: define predict method for BaseDecisionTree in sklearn frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishticode committed Dec 7, 2023
1 parent a08481c commit bd8435c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 0 additions & 3 deletions ivy/functional/frontends/sklearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def score(self, X, y, sample_weight=None):
def fit(self, X, y, **kwargs):
raise NotImplementedError

def predict(self, X):
raise NotImplementedError


class TransformerMixin:
def fit_transform(self, X, y=None, **fit_params):
Expand Down
18 changes: 17 additions & 1 deletion ivy/functional/frontends/sklearn/tree/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,23 @@ def _fit(
return self

def predict(self, X, check_input=True):
raise NotImplementedError
proba = self.tree_.predict(X)
n_samples = X.shape[0]

# Classification

if self.n_outputs_ == 1:
return ivy.gather(self.classes_, ivy.argmax(proba, axis=1), axis=0)

else:
class_type = self.classes_[0].dtype
predictions = ivy.zeros((n_samples, self.n_outputs_), dtype=class_type)
for k in range(self.n_outputs_):
predictions[:, k] = ivy.gather(
self.classes_[k], ivy.argmax(proba[:, k], axis=1), axis=0
)

return predictions

def apply(self, X, check_input=True):
raise NotImplementedError
Expand Down

0 comments on commit bd8435c

Please sign in to comment.