mne-tools / mne-features

MNE-Features software for extracting features from multivariate time series
https://mne-tools.github.io/mne-features/
BSD 3-Clause "New" or "Revised" License
142 stars 32 forks source link

Set frequency bands value while extracting features #56

Open talhaanwarch opened 4 years ago

talhaanwarch commented 4 years ago

I am trying to extract frequency band features using following way

feature=['energy_freq_bands','pow_freq_bands','line_length', 'kurtosis', 'ptp_amp', 'skewness']
fe = FeatureExtractor(sfreq=128, selected_funcs=feature)
X_new=fe.fit_transform(X)

It throwing me following error 'The entries of the givenfreq_bandsparameter (%s) must be positive and less than the Nyquist 'frequency.' % str(freq_bands).

So how can I remove the 100Hz frequency value limit from ['energy_freq_bands','pow_freq_bands'] while extracting features. I mean how can I just set freq_bands=np.array([0.5, 4., 8., 13.,30.]) without changing much things

talhaanwarch commented 4 years ago

One way is to do it following way using user-defined features

from mne_features.univariate   import compute_pow_freq_bands
def pow_freq(x):
  return compute_pow_freq_bands(128,x,freq_bands=np.array([0.5, 4., 8., 13.,30.]))
def energy_freq(x):
  return compute_energy_freq_bands(128,x,freq_bands=np.array([0.5, 4., 8., 13.,30.]))

selected_funcs = [('powfreq', pow_freq),('energyfreq',energy_freq),'line_length', 'kurtosis', 'ptp_amp', 'skewness']

But energyfreq is giving a strange warning and setting accuracy to NaN. Whereas powfreq is working correctly.

Issue with energyfreq is as follow

Cross-validation accuracy score = nan (+/- nan)
/usr/local/lib/python3.6/dist-packages/sklearn/model_selection/_split.py:296: FutureWarning: Setting a random_state has no effect since shuffle is False. This will raise an error in 0.24. You should leave random_state to its default (None), or set shuffle=True.
  FutureWarning
/usr/local/lib/python3.6/dist-packages/sklearn/model_selection/_validation.py:536: FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details: 
ValueError: Data to be filtered must be real floating, got int64

  FitFailedWarning)
/usr/local/lib/python3.6/dist-packages/sklearn/model_selection/_validation.py:536: FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details: 
ValueError: Data to be filtered must be real floating, got int64

  FitFailedWarning)

Please check this colab file for reproducing the problem

agramfort commented 4 years ago

your data is of dtype int64

do:

scores = cross_val_score(pipe, data.astype(float), y, cv=skf)

and it works

talhaanwarch commented 4 years ago

Thanks. In both cases, the data type is int64, but in the case of pow_freq it worked and in another case energy_freq it did not. But changing data type to float it worked

talhaanwarch commented 4 years ago

i figured out this is the issue with compute_energy_freq_bands that required data in float64 data type. Converting data to float64 will increase the computational time and space.

agramfort commented 4 years ago

int64 and float64 are the same size. 64 bits per entry. It just needs to be fixed in mne-features.