[Mne_analysis] GeneralizingEstimator with incremental learning / .partial_fit

Giulia Gennari giulia.gennari1991 at gmail.com
Thu Aug 6 09:54:37 EDT 2020
Search archives:

        External Email - Use Caution        

Dear Jean-Rémi,

Thank you for the nice suggestion!

Just to make sure that this is working (I apologize for my ignorance):

When I run:
model = SGDClassifier(loss='log', class_weight='balanced')
model.fit = model.partial_fit
slider1 = SlidingEstimator(model, scoring='roc_auc')
slider1.fit(X_train, y_train)

or

clf = make_pipeline(Vectorizer(), StandardScaler(), model)
slider2 = SlidingEstimator(clf, scoring='roc_auc')
slider2.fit(X_train, y_train)

I do not get any error, while I would expect:

ValueError: class_weight 'balanced' is not supported for partial_fit.
In order to use 'balanced' weights, use
compute_class_weight('balanced', classes, y). Pass the resulting
weights as the class_weight parameter.


Since this is what I get with:
model.fit(X_train[:,:,single_time_point], y_train)

Is there a good reason for that? E.g. class weights are computed internally
beforehand by SlidingEstimator?

Thank you again!

Giulia

On Wed, Aug 5, 2020 at 7:18 PM Jean-Rémi KING <jeanremi.king at gmail.com>
wrote:

>         External Email - Use Caution
>
> Hi Giulia,
>
> I think you should be able to change the method:
>
> model = sklearn.linear_model.SGDClassifier()
> model.fit = model.partial_fit
> slider = mne.decoding.SlidingEstimator(model)
> for X, y in train_batches:
>     slider.fit(X, y)
>
> Best
>
> JR
>
> On Wed, 5 Aug 2020 at 18:40, Giulia Gennari <giulia.gennari1991 at gmail.com>
> wrote:
>
>>         External Email - Use Caution
>>
>> Hi!
>>
>> I would need to try decoding with incremental learning (EEG data).
>> I was planning to use logistic regression by means of the SGDClassifier
>> <https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html>
>>  .
>> I would then need to call .partial_fit to make my estimator learn on each
>> of my training sets.
>> However:
>>
>> 'GeneralizingEstimator' object has no attribute 'partial_fit'
>>
>> Same issue for SlidingEstimator.
>> Is there a way to work around this limitation?
>>
>> Thank you so so much in advance!
>>
>> Giulia Gennari
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200806/3f539252/attachment-0001.html 


More information about the Mne_analysis mailing list