10000 [BUG] fix `RotationForest` for a custom `base_estimator` by fkiraly · Pull Request #8270 · sktime/sktime · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[BUG] fix RotationForest for a custom base_estimator #8270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions sktime/classification/sklearn/_rotation_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def __init__(

super().__init__()

if self.base_estimator is None:
self._base_estimator = DecisionTreeClassifier(criterion="entropy")
else:
self._base_estimator = self.base_estimator

def fit(self, X, y):
"""Fit a forest of trees on cases (X,y), where y is the target variable.

Expand Down Expand Up @@ -185,9 +190,6 @@ def fit(self, X, y):
start_time = time.time()
train_time = 0

if self.base_estimator is None:
self._base_estimator = DecisionTreeClassifier(criterion="entropy")

# remove useless attributes
self._useful_atts = ~np.all(X[1:] == X[:-1], axis=0)
X = X[:, self._useful_atts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
__author__ = ["MatthewMiddlehurst"]

import pytest
from sklearn.linear_model import LogisticRegression
from sklearn.utils.estimator_checks import parametrize_with_checks

from sktime.classification.sklearn import ContinuousIntervalTree, RotationForest
from sktime.tests.test_switch import run_test_for_class

ALL_SKLEARN_CLASSIFIERS = [RotationForest, ContinuousIntervalTree]

INSTANCES_TO_TEST = [
RotationForest(n_estimators=3),
RotationForest(n_estimators=3, base_estimator=LogisticRegression()),
ContinuousIntervalTree(),
]


@pytest.mark.skipif(
not run_test_for_class(ALL_SKLEARN_CLASSIFIERS),
reason="run test only if softdeps are present and incrementally (if requested)",
)
@parametrize_with_checks([RotationForest(n_estimators=3), ContinuousIntervalTree()])
@parametrize_with_checks(INSTANCES_TO_TEST)
def test_sklearn_compatible_estimator(estimator, check):
"""Test that sklearn estimators adhere to sklearn conventions."""
try:
Expand Down
0