Skip to content

[MRG+1] Isotonic calibration - #1176

Closed
agramfort wants to merge 8 commits into
scikit-learn:masterfrom
agramfort:isotonic_calibration
Closed

agramfort wants to merge 8 commits into
scikit-learn:masterfrom
agramfort:isotonic_calibration

Conversation

@agramfort

Copy link
Copy Markdown
Member

calibration module with platt and Isotonic calibration.

A few issues :

  • nice calibration plots
  • add tests for metrics
  • add narrative doc
  • speed up the test execution as much as possible
  • fix multi-class support for the isotonic regression method

Comment thread examples/plot_calibration.py Outdated

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.

@mblondel

Copy link
Copy Markdown
Member

"Brier score" seems to be the accepted name so I'm inclined to keep it that way.

IIRC, in "Transforming Classifier Scores into Accurate Multiclass Probability Estimates" (KDD 2002), they study several methods and conclude that one-vs-rest in the most practical solution.

@agramfort

Copy link
Copy Markdown
Member Author

"Brier score" seems to be the accepted name so I'm inclined to keep it
that way.

hum. I am sure it will pass the consistency brigade :)

IIRC, in "Transforming Classifier Scores into Accurate Multiclass
Probability Estimates" (KDD 2002), they study several methods and conclude
that one-vs-rest in the most practical solution.

ok so IsotonicCalibrator should use OneVsRestClassifier internally and
the proba are estimated for each pair and normalized to sum to 1
right?

@mblondel

Copy link
Copy Markdown
Member

I guess IsotanicCalibrator could take the 2d output of decision_function as an input and produce multiclass probabilities. Please read the reference I gave, I don't remember it well.

@ogrisel

ogrisel commented Sep 24, 2012

Copy link
Copy Markdown
Member

About the Brier score being not a sklearn consistent score (higher == worst in this case): I don't really know what would be best as the sklearn naming convention is indeed conflicting with this official name.

http://en.wikipedia.org/wiki/Brier_score

I would be +0 for keeping the brier_score name and emphasizing the fact that higher values means less confident estimates in the docstring and the narrative doc.

Comment thread sklearn/metrics/metrics.py Outdated

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.

PEP 257

@agramfort

Copy link
Copy Markdown
Member Author

I guess IsotanicCalibrator could take the 2d output of decision_function
as an input and produce multiclass probabilities. Please read the reference
I gave, I don't remember it well.

indeed in there experimental results they use OvR

I think it's a good idea to fit an IR to each decision score.

@agramfort

Copy link
Copy Markdown
Member Author

About the Brier score being not a sklearn consistent score (higher ==
worst in this case): I don't really no what would be best as the sklearn
naming convention is indeed conflicting with this official name.

http://en.wikipedia.org/wiki/Brier_score

I would be +0 for keeping the brier_score name and emphasizing the fact
that higher values means less confident estimates in the docstring and the
narrative doc.

can we call it brier ? or brier_error ? as it's a mean squared error
on the proba.

@mblondel

Copy link
Copy Markdown
Member

One solution would be to introduce decorators to label some functions as scores and others as losses. Of course, this is out of the scope of this PR... (This idea would also be useful to define whether a metric accepts predicted labels or predicted scores, c.f. the AUC issue)

Another solution is to introduce a function negative_brier_score, which is just the brier score multiplied by -1. But I think it's important to use the most commonly used names so -1 for this solution.

So adding a note to the documentation as @ogrisel suggested seems like a good temporary solution to me.

@mblondel mblondel mentioned this pull request Sep 29, 2012
@paolo-losi

Copy link
Copy Markdown
Member

Some quick comments ...

  • +1 for the name brier_score
  • I would consider passing a cross validation class to IsotonicCalibration.__init__().
    Using one fold (oo_bag data) in the case of small number of samples problems could be insufficient.
  • I would also add log_likelihood_loss for probability estimation evaluation.
    See "The problem with the Brier score" by Stephen Jewson
  • I would warn in the doc agains using Isotonic Calibration with less than 1000 calibration samples since it tends
    overfit (Platt's calibration is advisable in that case). I should be able to find a paper on the subject if anyone
    is interested
  • +1 for default number of bins = sqrt(samples) for calibration_plot

@agramfort

Copy link
Copy Markdown
Member Author

hi paolo,

thanks for this valuable feedback. I won't work on this in the next few
days to if you want to improve on my PR please do so. I'll merge your
commits into my PR.

@ogrisel

ogrisel commented Sep 30, 2012

Copy link
Copy Markdown
Member

I would warn in the doc agains using Isotonic Calibration with less than 1000 calibration samples since it tends overfit (Platt's calibration is advisable in that case). I should be able to find a paper on the subject if anyone is interested

+1

@mblondel

mblondel commented Feb 1, 2013

Copy link
Copy Markdown
Member

Using one fold (oo_bag data) in the case of small number of samples problems could be insufficient.

If you use more than one fold, how do you combine the results?

Comment thread sklearn/calibration.py Outdated

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.

The above is not consistent with our API. So, a CV object passed to the constructor is a good idea in any case.

@agramfort

Copy link
Copy Markdown
Member Author

rebased on master + address some comments

I needed a coding break... ;)

If you feel like playing with it please do...

@ogrisel

ogrisel commented Feb 26, 2013

Copy link
Copy Markdown
Member

You should provide a default value for the estimator constructor param maybe, a baseline that is fast such as MultinomialNB that is both fast, has few hyperparameters and benefit from calibration:

======================================================================
ERROR: sklearn.tests.test_common.test_all_estimators
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/travis/build/scikit-learn/scikit-learn/sklearn/tests/test_common.py", line 68, in test_all_estimators
    estimator = Estimator()
TypeError: __init__() takes exactly 2 arguments (1 given)

@agramfort

Copy link
Copy Markdown
Member Author

I've rebased and cleanup the example. I'am open to discussion regarding API and multiclass handling. I don't know how to take care of the OOB to estimate the probas.

@agramfort

Copy link
Copy Markdown
Member Author

@mblondel any chance you can provide feedback on this? I'll get back to it tomorrow morning.

Comment thread sklearn/calibration.py Outdated

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 about generating the calibration data with a cv object (parameter of the constructor)?

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling bd727f3 on agramfort:isotonic_calibration into * on scikit-learn:master*.

@agramfort

Copy link
Copy Markdown
Member Author

@ogrisel @mblondel have a look :)

Comment thread sklearn/metrics/metrics.py Outdated

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.

space before ":" ;)

@jmetzen
jmetzen force-pushed the isotonic_calibration branch from 346e75e to 1a2a9ae Compare February 18, 2015 11:16
@jmetzen

jmetzen commented Feb 18, 2015

Copy link
Copy Markdown
Member

Alright, I squashed it now into 5 generic commits (calibration module, brier score, tests, examples, narrative doc). I've also added @mblondel to the list of authors in calibration.py

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) to 95.06% when pulling 1a2a9ae on agramfort:isotonic_calibration into f20ff86 on scikit-learn:master.

@agramfort

Copy link
Copy Markdown
Member Author

I pushed a couple of commits (cosmit + coverage improvement). The coverage could be slightly improved. Currently we have 95% coverage.

@ogrisel

ogrisel commented Feb 19, 2015

Copy link
Copy Markdown
Member

Alright, I squashed it now into 5 generic commits (calibration module, brier score, tests, examples, narrative doc). I've also added @mblondel to the list of authors in calibration.py

Great, thank you very much!

@ogrisel

ogrisel commented Feb 19, 2015

Copy link
Copy Markdown
Member

The coverage could be slightly improved. Currently we have 95% coverage.

Indeed there is a couple of exceptions that should be covered by additional assert_raises or assert_raise_message checks:

https://coveralls.io/builds/1947924/source?filename=sklearn%2Fcalibration.py

It should be easy to raise the coverage close to 99% on that file.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.03%) to 95.07% when pulling 838b06e on agramfort:isotonic_calibration into f20ff86 on scikit-learn:master.

@jmetzen
jmetzen force-pushed the isotonic_calibration branch from 838b06e to db13132 Compare February 19, 2015 19:14
@jmetzen

jmetzen commented Feb 19, 2015

Copy link
Copy Markdown
Member

I've added some assert_raises, coverage of calibration.py should now be effectively 100%

@ogrisel

ogrisel commented Feb 20, 2015

Copy link
Copy Markdown
Member

Thanks. I think this is ok for merge. @agramfort @mblondel any more comments?

@agramfort

Copy link
Copy Markdown
Member Author

+1 for merge on my side.

@mblondel

Copy link
Copy Markdown
Member

Just to confirm: do we want really want sigmoid_calibration to be a public function?

Other than that +1 as well!

@agramfort

agramfort commented Feb 20, 2015 via email

Copy link
Copy Markdown
Member Author

@ogrisel

ogrisel commented Feb 20, 2015

Copy link
Copy Markdown
Member

+1 for a private sigmoid_calibration as well. I will do the change and merge.

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.

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.

Done (these tests are pretty nice; I didn't know they exist). I had to modify test_invariance_string_vs_numbers_labels() slightly such that pos_label is also set for THRESHOLDED_METRICS

@ogrisel

ogrisel commented Feb 20, 2015

Copy link
Copy Markdown
Member

Oops I had already merged, I will cherry pick this.

@ogrisel

ogrisel commented Feb 20, 2015

Copy link
Copy Markdown
Member

Done! 🍻 Thank you very much everyone!

@ogrisel ogrisel closed this Feb 20, 2015
@agramfort

agramfort commented Feb 20, 2015 via email

Copy link
Copy Markdown
Member Author

@GaelVaroquaux

GaelVaroquaux commented Feb 20, 2015 via email

Copy link
Copy Markdown
Member

@jmetzen

jmetzen commented Feb 20, 2015

Copy link
Copy Markdown
Member

Thanks for merging! 🍻

@mblondel

Copy link
Copy Markdown
Member

Congrats!

When was this effort started again? Two? Three years ago? :)

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.

This raises a warning as GaussianNB doesn't support sample_weights. If this is expected behavior, I think the warning should be caught.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Do we really want examples to raise warnings? ;) I thought the use of a classifier that doesn't have sample_weights was intentional.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

is it me or there is no use of sample_weight in this example?

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 thought it was used internally in the calibration. But you are right, it shouldn't warn if it is not used. Will investigate!

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.