Skip to content

[MRG+1] Adding a fit_predict method for the GMM#4593

Merged
amueller merged 1 commit intoscikit-learn:masterfrom
clorenz7:gmm_fit_predict
Apr 30, 2015
Merged

[MRG+1] Adding a fit_predict method for the GMM#4593
amueller merged 1 commit intoscikit-learn:masterfrom
clorenz7:gmm_fit_predict

Conversation

@clorenz7
Copy link
Copy Markdown

With low iterations, the prediction might not be 100% accurate due to
the final maximization step in the EM algorithm.

See issue:
#4579

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use the _check_fitted_model: do a git grep _check_fitted_model to see examples in the code base.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this comment is no longer relevant in light of the other comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could that ever happen?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would return directly:

return self._fit(X, y).argmax(axis=1)

and make sure that _fit can never return None (make it raise a ValueError or similar with a meaningful error message otherwise).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could happen in the case when n_iter == 0. You're right that never returning None is better, so I added a check to run score_samples to get the correct output value in that case (that apparently happens when running an HMM). My current idea is just to output zeros because the idea of n_iter=0 seems to be to quickly initialize a model.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Apr 14, 2015

I am not sure I understand the travis failures, it probably requires to launch a debugger.

@clorenz7
Copy link
Copy Markdown
Author

@ogrisel Besides addressing your comments, I changed the GMM subclass fit method to _fit, and added some additional test cases.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Apr 15, 2015

For the travis failure, a solution would be to not implement fit_predict for DPGMM and VBGMM, it is possible to introduce a new _BaseGMM abstract base class with most of the current methods of GMM in it and then make GMM, ``DPGMMandVBGMM`. Finally only implement `fit_predict` in the `GMM` class.

git grep ABCMeta to see how we create abstract base classes in sklearn that support both Python 2 and Python 3 in the same code base.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Apr 15, 2015

Ah alright, ignore my last comment, I had an internet connection pbm and could not post it when I first wrote it. Now I see that fixed the problems with the subclasses.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for having updated that test.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Apr 15, 2015

@eyaler does that PR meet your requirements from #4579?

LGTM, +1 for merge on my side.

@clorenz7 could please just add a new entry in the section on the new features for 0.17.dev0 in the doc/whats_new.rst file?

@ogrisel ogrisel changed the title Adding a fit_predict method for the GMM [MRG+1] Adding a fit_predict method for the GMM Apr 15, 2015
@clorenz7
Copy link
Copy Markdown
Author

@ogrisel Added what's new. Thanks for all your help!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to document its return value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants