Version : mne-1.0.3
I have encountered this error every time i run a pipeline with validate as True. The accuracy of the code significantly changes with this and its not accurate.
here is the code
‘’’
raw= mne.io.read_raw_edf(‘ST7011J0-PSG.edf’,stim_channel=‘auto’,preload=True)
annot = mne.read_annotations(‘ST7011JP-Hypnogram.edf’)
raw.set_annotations(annot, emit_warning=True)
events, _ = mne.events_from_annotations(raw, event_id=event_id, chunk_duration=30.)
tmax = 30. - 1. / raw.info[‘sfreq’] # tmax in included
epochs=mne.Epochs(raw=raw, events=events,event_id=event_id, tmin=0., tmax=tmax, baseline=None)
‘’’
**
**
def eeg_power_band(epochs):
#EEG relative power band feature extraction.
This function takes an ``mne.Epochs`` object and creates EEG features based
on relative power in specific frequency bands that are compatible with
scikit-learn.
Parameters
----------
epochs : Epochs
The data.
Returns
-------
X : numpy array of shape [n_samples, 5]
Transformed data.
"""
# specific frequency bands
FREQ_BANDS = {"delta": [0.1, 4.5],
"theta": [4.5, 8.5],
"alpha": [8.5, 11.5],
"sigma": [11.5, 15.5],
"beta": [15.5, 30]}
psds, freqs = psd_welch(epochs_train, picks='eeg', fmin=0.5, fmax=30.)
psds, freqs = psd_welch(epochs_test, picks='eeg', fmin=0.5, fmax=30.)
# Normalize the PSDs
psds /= np.sum(psds, axis=-1, keepdims=True)
global X
X = []
for fmin, fmax in FREQ_BANDS.values():
psds_band = psds[:, :, (freqs >= fmin) & (freqs < fmax)].mean(axis=-1)
X.append(psds_band.reshape(len(psds), -1))
return np.concatenate(X, axis=1)
return Xer(l_freq=0, h_freq=30)
**
**
pipe=make_pipeline(FunctionTransformer(eeg_power_band,validate=True),RandomForestClassifier(n_estimators=20,criterion=‘entropy’,class_weight=‘balanced’, random_state=42))
**
**
yt_train = epochs_train.events[:, 2]
pipe.fit(epochs_train, yt_train)
**