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
Improving feature names #42
Conversation
…returns a dataframe with a meaningful multiindex).
mne_features/feature_extraction.py
Outdated
elif _params['ratios'] == 'only': | ||
return ratios_names | ||
else: | ||
return pow_names + ratios_names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not really clean. This gymnastic should be done via the function pow_freq_bands. You have some logic in a function agnostic class which percolates from a custom function. You should attach this logic to the pow_freq_bands callable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this is not clean. This first commit was just to allow @l-omar-chehab to move on (and have meaning feature names for compute_pow_freq_bands
). Now, we can think about making it nice.
Here is one idea on how the feature names could be "attached" to the feature functions. If called with
So that, in
where In the code above,
... you get the idea! If a feature function does not have a |
I would do it like this:
by adding an attribute to the function. func.get_feature_names should expect the same parameters as func to make things easy. clear? |
`_compute_pow_freq_bands_feat_names` in univariate.py + changes in feature_extraction.py. * Minor changes in tests and examples to get rid of several warnings (issue mne-tools#44).
Codecov Report
@@ Coverage Diff @@
## master #42 +/- ##
==========================================
+ Coverage 92.74% 93.12% +0.38%
==========================================
Files 10 10
Lines 1089 1164 +75
==========================================
+ Hits 1010 1084 +74
- Misses 79 80 +1
Continue to review full report at Codecov.
|
mne_features/feature_extraction.py
Outdated
_feature_func = _get_python_func(self.func) | ||
_params = self.get_params() | ||
if hasattr(_feature_func, 'get_feature_names'): | ||
self.feature_names = _feature_func.get_feature_names(X, **_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that calling transform affects the state of the object. Only a fit is allowed to do this. Can you see a way out? also any attribute that is data dependent should end with _
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Then, what about
def fit(self, X, y=None):
"""Fit the FeatureFunctionTransformer (does not extract features).
Parameters
----------
X : ndarray, shape (n_channels, n_times)
y : ignored
Returns
-------
self
"""
self._check_input(X)
_feature_func = _get_python_func(self.func)
_params = self.get_params()
if hasattr(_feature_func, 'get_feature_names'):
self.feature_names_ = _feature_func.get_feature_names(X, **_params)
return self
in FeatureFunctionTransformer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is ok in terms of API but _params = self.get_params()
could be in the if block
; only used to get feature names when this is possible).
@agramfort If you're OK and if Travis is OK, it's good to go ! |
there is to test to check that the feature names are correct. Please add one. thx |
Test added ! |
fb = np.array([[4., 8.], [30., 70.]]) | ||
ratios_col_names = ['ch0_0_1', 'ch0_1_0', 'ch1_0_1', 'ch1_1_0', | ||
'ch2_0_1', 'ch2_1_0'] | ||
pow_col_names = ['ch0_0', 'ch0_1', 'ch1_0', 'ch1_1', 'ch2_0', 'ch2_1'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no way to have more explicit names likes alpha, beta etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could improve that but, at some point, the user would need to name the frequency bands he wishes to use. What about allowing the freq_bands
parameter in compute_pow_freq_bands
to be a dict as the one below?
freq_bands = {'delta': [0.5, 4],
'theta': [4, 8],
'alpha': [8, 13],
'beta': [13, 30],
'low-gamma': [30, 70],
'high-gamma': [70, 100]}
yes +1 !
|
`compute_energy_freq_bands`) to be a dict with band names as keys. Added feature names for `compute_enregy_freq_bands` + updated tests.
The last commit improves the feature names when
|
Thanks |
This PR aims at having more meaningful feature names when
extract_features
is called withreturn_df = True
.