Skip to content

Commit

Permalink
Maintenance (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannfaouzi committed Oct 28, 2021
1 parent 4729b52 commit 16e1703
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ formats:
- none
requirements_file: requirements.txt
python:
version: 3.7
version: 3.8
pip_install: true
install:
- requirements: docs/requirements.txt
Expand Down
12 changes: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
python.version: '3.9'
numpy.version: '1.*'
scipy.version: '1.*'
scikit-learn.version: '0.*'
scikit-learn.version: '1.*'
joblib.version: '0.*'
numba.version: '0.*'

Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
python.version: '3.8'
numpy.version: '1.*'
scipy.version: '1.*'
scikit-learn.version: '0.*'
scikit-learn.version: '1.*'
joblib.version: '0.*'
numba.version: '0.*'

Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
python.version: '3.9'
numpy.version: '1.*'
scipy.version: '1.*'
scikit-learn.version: '0.*'
scikit-learn.version: '1.*'
joblib.version: '0.*'
numba.version: '0.*'

Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
python.version: '3.8'
numpy.version: '1.*'
scipy.version: '1.*'
scikit-learn.version: '0.*'
scikit-learn.version: '1.*'
joblib.version: '0.*'
numba.version: '0.*'

Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
python.version: '3.9'
numpy.version: '1.*'
scipy.version: '1.*'
scikit-learn.version: '0.*'
scikit-learn.version: '1.*'
joblib.version: '0.*'
numba.version: '0.*'

Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
python.version: '3.8'
numpy.version: '1.*'
scipy.version: '1.*'
scikit-learn.version: '0.*'
scikit-learn.version: '1.*'
joblib.version: '0.*'
numba.version: '0.*'

Expand Down
6 changes: 3 additions & 3 deletions examples/classification/plot_tsbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
clf = TSBF(random_state=43, bins=5)
clf.fit(X_train, y_train)

plt.bar(np.arange(clf.n_features_), clf.feature_importances_)
plt.bar(np.arange(clf.n_features_in_), clf.feature_importances_)
plt.title('Feature importance scores')
plt.xticks(np.arange(clf.n_features_),
['feature {}'.format(i) for i in range(clf.n_features_)],
plt.xticks(np.arange(clf.n_features_in_),
['feature {}'.format(i) for i in range(clf.n_features_in_)],
rotation=90)
plt.ylabel("Mean decrease in impurity")
plt.tight_layout()
Expand Down
4 changes: 4 additions & 0 deletions pyts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def fit_transform(self, X, y=None, **fit_params):
class UnivariateClassifierMixin:
"""Mixin class for all univariate classifiers in pyts."""

_estimator_type = "classifier"

def score(self, X, y, sample_weight=None):
"""
Return the mean accuracy on the given test data and labels.
Expand Down Expand Up @@ -104,6 +106,8 @@ def score(self, X, y, sample_weight=None):
class MultivariateClassifierMixin:
"""Mixin class for all multivariate classifiers in pyts."""

_estimator_type = "classifier"

def score(self, X, y, sample_weight=None):
"""
Return the mean accuracy on the given test data and labels.
Expand Down
2 changes: 1 addition & 1 deletion pyts/classification/tests/test_time_series_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_actual_results_fixed_indices(indices, arr_desired):
def test_attributes_time_series_forest(params):
"""Test the attributes of a fitted instance of TimeSeriesForest."""
real_attributes = ['base_estimator_', 'classes_', 'estimators_',
'feature_importances_', 'indices_', 'n_features_',
'feature_importances_', 'indices_', 'n_features_in_',
'oob_decision_function_', 'oob_score_']
fake_attributes = ['yolo', 'whoopsy', 'mistake_were_made_']

Expand Down
2 changes: 1 addition & 1 deletion pyts/classification/tests/test_tsbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def test_attributes_tsbf(X, y, params):
assert clf.feature_importances_.shape == (n_features,)
assert clf.interval_indices_.ndim == 2
assert isinstance(clf.min_subsequence_size_, (int, np.integer))
assert clf.n_features_ == n_features
assert clf.n_features_in_ == n_features
if params.get('oob_score', TSBF().get_params()['oob_score']):
assert clf.oob_decision_function_.shape == (n_samples, n_classes)
assert isinstance(clf.oob_score_, (float, np.floating))
Expand Down
8 changes: 6 additions & 2 deletions pyts/classification/time_series_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class TimeSeriesForest(BaseEstimator, UnivariateClassifierMixin):
of the windows. The second column consists of the ending indices
(excluded) of the windows.
n_features_ : int
n_features_in_ : int
The number of features when ``fit`` is performed.
oob_decision_function_ : None or array, shape = (n_samples, n_classes)
Expand Down Expand Up @@ -516,7 +516,11 @@ def fit(self, X, y):
self.estimators_ = self._pipeline['rfc'].estimators_
self.feature_importances_ = self._pipeline['rfc'].feature_importances_
self.indices_ = self._pipeline['fe'].indices_
self.n_features_ = self._pipeline['rfc'].n_features_
self.n_features_in_ = (
self._pipeline['rfc'].n_features_in_
if hasattr(self._pipeline['rfc'], 'n_features_in_')
else self._pipeline['rfc'].n_features_
)
self.oob_decision_function_ = getattr(
self._pipeline['rfc'], 'oob_decision_function_', None)
self.oob_score_ = getattr(self._pipeline['rfc'], 'oob_score_', None)
Expand Down
16 changes: 13 additions & 3 deletions pyts/classification/tsbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ class TSBF(BaseEstimator, UnivariateClassifierMixin):
min_subsequence_size_ : int
The actual minimum length of the subsequences.
n_features_ : int
n_features_in_ : int
The number of features when ``fit`` is performed.
oob_decision_function_ : None or array, shape = (n_samples, n_classes)
Expand Down Expand Up @@ -660,7 +660,13 @@ def fit(self, X, y):
rfc.fit(X_features, y_features)
X_oob_proba = rfc.oob_decision_function_.reshape(
n_samples, n_subsequences, n_classes)
if np.isnan(X_oob_proba).any():

# Check for subsequences without OOB scores
no_oob_scores = (
(np.isnan(X_oob_proba).any() or
np.all(X_oob_proba == 0., axis=2).any())
)
if no_oob_scores:
raise ValueError(
"At least one sample was never left out during the bootstrap. "
"Increase the number of trees (n_estimators)."
Expand All @@ -683,7 +689,11 @@ def fit(self, X, y):
self.feature_importances_ = clf.feature_importances_
self.interval_indices_ = feature_extractor.interval_indices_
self.min_subsequence_size_ = feature_extractor.min_subsequence_size_
self.n_features_ = clf.n_features_
self.n_features_in_ = (
clf.n_features_in_
if hasattr(clf, 'n_features_in_')
else clf.n_features_
)
self.oob_decision_function_ = getattr(
clf, 'oob_decision_function_', None)
self.oob_score_ = getattr(clf, 'oob_score_', None)
Expand Down

0 comments on commit 16e1703

Please sign in to comment.