Skip to content

Commit

Permalink
Warning no relevant features (blue-yonder#330)
Browse files Browse the repository at this point in the history
* add warning if no feature relevant

* unit test for no relevant feature warning
  • Loading branch information
MaxBenChrist authored Sep 28, 2017
1 parent 8611784 commit 54c5431
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion tests/units/feature_selection/test_relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pandas as pd
import pytest
import mock
import warnings

from tsfresh.feature_selection.relevance import infer_ml_task, calculate_relevance_table, combine_relevance_tables, \
get_feature_type
Expand Down Expand Up @@ -86,6 +87,17 @@ def test_target_real_calls_correct_tests(self, significance_test_feature_binary_
significance_test_feature_binary_mock.assert_called_once_with(X['feature_binary'], y=y_real)
significance_test_feature_real_mock.assert_called_once_with(X['feature_real'], y=y_real)

@mock.patch('tsfresh.feature_selection.relevance.target_real_feature_real_test')
@mock.patch('tsfresh.feature_selection.relevance.target_real_feature_binary_test')
def test_warning_for_no_relevant_feature(self, significance_test_feature_binary_mock,
significance_test_feature_real_mock, X, y_real):
significance_test_feature_binary_mock.return_value = 0.95
significance_test_feature_real_mock.return_value = 0.95

with mock.patch('logging.Logger.warning') as m:
relevance_table = calculate_relevance_table(X, y_real, n_jobs=0, ml_task="regression")
m.assert_called_with('No feature was found relevant for regression for fdr level = 0.05. '
'Consider using a lower fdr level or other features.')

class TestCombineRelevanceTables:
@pytest.fixture()
Expand Down Expand Up @@ -130,4 +142,4 @@ def test_constant(self):

def test_real(self):
feature = pd.Series([0.0, 1.0, 2.0])
assert 'real' == get_feature_type(feature)
assert 'real' == get_feature_type(feature)
6 changes: 5 additions & 1 deletion tsfresh/feature_selection/relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ def calculate_relevance_table(X, y, ml_task='auto', n_jobs=defaults.N_PROCESSES,
pool.close()
pool.terminate()
pool.join()


if sum(relevance_table['relevant']) == 0:
_logger.warning("No feature was found relevant for {} for fdr level = {}. "
"Consider using a lower fdr level or other features.".format(ml_task, fdr_level))

return relevance_table


Expand Down

0 comments on commit 54c5431

Please sign in to comment.