Skip to content

Be more tolerant in check_array for CalibratedClassifierCV #13077

Closed

Description

@wdevazelhes

For our package http://github.com/metric-learn/metric-learn, the function CalibratedClassifierCV is very convenient for Weakly Supervised Learners, as it can make PairsClassifier estimators return a probability for a pair of points to be labeled as similar or dissimilar, when those return a decision function.

However, we currently cannot use it because our inputs can be 3D (example: pairs=[[[2.3, 5.4], [4.4, 5.6]], [[7.5, 1.2], [4.4, 5.6]]]), and CalibratedClassifierCV uses check_array with default parameters that does not allow 3D inputs.

However, other meta-estimators like GridSearchCV do not call check_array, so we can use them easily in metric-learn.

Is the check_array in CalibratedClassifierCV really useful or could we do without it ? If we could, I'd be happy to provide a PR to do so

Activity

  1. jnothman commented on Feb 3, 2019

    @jnothman
    Member
  2. wdevazelhes commented on Feb 4, 2019

    @wdevazelhes
    ContributorAuthor

    I just tested and the following checks in test_non_meta_estimators do not work (the rest of scikit-learn's tests work): check_sample_weights_pandas_series, check_estimators_empty_data_messages, check_classifier_data_not_an_array, check_classifiers_train, check_classifiers_train(readonly_memmap=True), check_supervised_y_no_nan. However, if I add allow_nd=True in the check_array, every test work. I could just change that, but I also noticed several things:

    • CalibratedClassifierCV in fact does not inherit from MetaEstimatorMixin. Is it normal ? If it was, it wouldn't have to pass all these tests. However, I believe some of these tests should be tested and are not tested right now on meta-estimators, like check_sample_weights_pandas_series, check_classifier_data_not_an_array, (and maybe check_classifiers_train). Should I add them to tests on meta-estimators ?
    • I noticed that GridSearchCV uses _safe_split in order to support dataframes for instance, when splitting for the CV (which for CalibratedClassifierCV would solve check_sample_weights_pandas_series, check_classifier_data_not_an_array, and check_classifiers_train). Is it preferable to check_array(allow_nd=True) ?

    EDIT: Now that I think about it and after what @jnothman said about MetaEstimator doing little (#13485 (comment)), I don't think assumptions (or non-assomptions) on the input data are part of the definition of a MetaEstimator in the end, so maybe there's no need to add these tests for MetaEstimator

  3. connorbrinton commented on Apr 1, 2019

    @connorbrinton

    I think this issue is also related to #8710, which has to do with CalibratedClassifierCV's input validation in a pipeline context

  4. jnothman commented on Apr 4, 2019

    @jnothman
    Member

    I don't think assumptions (or non-assomptions) on the input data are part of the definition of a MetaEstimator in the end,

    I don't think it's part of the assumptions, but I think that as a library, scikit-learn should do what it can to place minimal constraints on the data in the case of meta-estimators. What is minimal will depend on the meta-estimator, however, so I'm not sure common tests is the right solution.

  5. wdevazelhes commented on Apr 4, 2019

    @wdevazelhes
    ContributorAuthor

    I don't think it's part of the assumptions, but I think that as a library, scikit-learn should do what it can to place minimal constraints on the data in the case of meta-estimators. What is minimal will depend on the meta-estimator, however, so I'm not sure common tests is the right solution.

    I understand, that makes sense

  6. bellet commented on Apr 4, 2019

    @bellet
    Contributor

    So would the addition of allow_nd=True in the check_array be the way to go then?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions