{"action":"created","issue":{"url":"https://api.github.com/repos/mne-tools/mne-features/issues/43","repository_url":"https://api.github.com/repos/mne-tools/mne-features","labels_url":"https://api.github.com/repos/mne-tools/mne-features/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/mne-tools/mne-features/issues/43/comments","events_url":"https://api.github.com/repos/mne-tools/mne-features/issues/43/events","html_url":"https://github.com/mne-tools/mne-features/pull/43","id":362221914,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE2OTk4OTQx","number":43,"title":"Use other methods than FFT to compute the PSD","user":{"login":"jbschiratti","id":22887703,"node_id":"MDQ6VXNlcjIyODg3NzAz","avatar_url":"https://avatars1.githubusercontent.com/u/22887703?v=4","gravatar_id":"","url":"https://api.github.com/users/jbschiratti","html_url":"https://github.com/jbschiratti","followers_url":"https://api.github.com/users/jbschiratti/followers","following_url":"https://api.github.com/users/jbschiratti/following{/other_user}","gists_url":"https://api.github.com/users/jbschiratti/gists{/gist_id}","starred_url":"https://api.github.com/users/jbschiratti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbschiratti/subscriptions","organizations_url":"https://api.github.com/users/jbschiratti/orgs","repos_url":"https://api.github.com/users/jbschiratti/repos","events_url":"https://api.github.com/users/jbschiratti/events{/privacy}","received_events_url":"https://api.github.com/users/jbschiratti/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-09-20T14:43:47Z","updated_at":"2018-10-01T12:57:07Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/mne-tools/mne-features/pulls/43","html_url":"https://github.com/mne-tools/mne-features/pull/43","diff_url":"https://github.com/mne-tools/mne-features/pull/43.diff","patch_url":"https://github.com/mne-tools/mne-features/pull/43.patch"},"body":"This PR aims at addressing #40 : the estimation of the PSD from the FFT of the data can sometimes be quite noisy. We propose to address that by allowing the PSD to be computed using Welch method (in case of \"sufficiently large\" windows, averaging should smooth the PSD a bit...), FFT or Multitaper.\r\n\r\nThe example below shows that using Welch method instead of the FFT can actually improve cross-validation classification scores (using ratios of band power as features).\r\n\r\nExample:\r\n\r\n```\r\nimport mne\r\nimport numpy as np\r\nfrom mne.datasets import sample\r\nfrom sklearn.linear_model import LogisticRegression\r\nfrom sklearn.model_selection import cross_val_score, KFold\r\nfrom sklearn.pipeline import Pipeline\r\nfrom sklearn.base import clone\r\nfrom sklearn.preprocessing import StandardScaler\r\n\r\nfrom mne_features.feature_extraction import extract_features\r\n\r\n###############################################################################\r\n# Let us import the data using MNE-Python and epoch it:\r\n\r\ndata_path = sample.data_path()\r\nraw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'\r\nevent_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'\r\ntmin, tmax = -0.2, 0.5\r\nevent_id = dict(aud_l=1, vis_l=3)\r\n\r\n# Setup for reading the raw data\r\nraw = mne.io.read_raw_fif(raw_fname, preload=True)\r\nraw.filter(.5, None, fir_design='firwin')\r\nevents = mne.read_events(event_fname)\r\npicks = mne.pick_types(raw.info, meg='grad', eeg=False)\r\n\r\n# Read epochs\r\nepochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks, proj=True,\r\n                    baseline=None, preload=True)\r\nlabels = epochs.events[:, -1]\r\n\r\n# get MEG and EEG data\r\ndata = epochs.get_data()\r\n\r\n###############################################################################\r\n# Prepare for the classification task:\r\npipe = Pipeline([('scaler', StandardScaler()),\r\n                 ('lr', LogisticRegression(random_state=42, solver='lbfgs'))])\r\ny = labels\r\n\r\n###############################################################################\r\n# Cross-validation score using different methods to compute the PSD of the\r\n# signal (FFT, Welch or Multitaper).\r\n\r\nkf = KFold(n_splits=3, random_state=42)\r\nselected_funcs = {'pow_freq_bands'}\r\nselected_freq_bands = np.array([0.5, 4., 8., 13., 30., 70.])\r\n\r\nfor psd_method in ['fft', 'welch', 'multitaper']:\r\n\r\n    X = extract_features(\r\n        data, raw.info['sfreq'], selected_funcs,\r\n        funcs_params={'pow_freq_bands__ratios': 'all',\r\n                      'pow_freq_bands__freq_bands': selected_freq_bands,\r\n                      'pow_freq_bands__psd_method': psd_method})\r\n    scores = cross_val_score(clone(pipe), X, y, cv=kf)\r\n\r\n    ###########################################################################\r\n    # Print the cross-validation score:\r\n\r\n    print('Cross-validation accuracy score with %s method = %1.3f '\r\n          '(+/- %1.5f)' % (psd_method, np.mean(scores), np.std(scores)))\r\n```\r\nOutputs: \r\n```\r\nCross-validation accuracy score with fft method = 0.848 (+/- 0.02690)\r\nCross-validation accuracy score with welch method = 0.910 (+/- 0.02615)\r\nCross-validation accuracy score with multitaper method = 0.869 (+/- 0.05505)\r\n```"},"comment":{"url":"https://api.github.com/repos/mne-tools/mne-features/issues/comments/425897394","html_url":"https://github.com/mne-tools/mne-features/pull/43#issuecomment-425897394","issue_url":"https://api.github.com/repos/mne-tools/mne-features/issues/43","id":425897394,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNTg5NzM5NA==","user":{"login":"agramfort","id":161052,"node_id":"MDQ6VXNlcjE2MTA1Mg==","avatar_url":"https://avatars2.githubusercontent.com/u/161052?v=4","gravatar_id":"","url":"https://api.github.com/users/agramfort","html_url":"https://github.com/agramfort","followers_url":"https://api.github.com/users/agramfort/followers","following_url":"https://api.github.com/users/agramfort/following{/other_user}","gists_url":"https://api.github.com/users/agramfort/gists{/gist_id}","starred_url":"https://api.github.com/users/agramfort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agramfort/subscriptions","organizations_url":"https://api.github.com/users/agramfort/orgs","repos_url":"https://api.github.com/users/agramfort/repos","events_url":"https://api.github.com/users/agramfort/events{/privacy}","received_events_url":"https://api.github.com/users/agramfort/received_events","type":"User","site_admin":false},"created_at":"2018-10-01T12:57:07Z","updated_at":"2018-10-01T12:57:07Z","author_association":"MEMBER","body":"merge if you're done\r\n\r\ndoes it mean we should rerun the results from iccassp paper ? as I suspect you changed the defaults results with this PR."}}
{"actor":{"display_login":"agramfort"}}