Skip to content

Margin sampling fails with a bad error message if there is only one class in the predictions #9

@AlexandreAbraham

Description

@AlexandreAbraham

We should not expect the classifier to return at least several proba. The error is:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-30-2b90468e1fd1> in <module>
      4                                   n_init_points,
      5                                   base_model,
----> 6                                   semi_model)
<ipython-input-25-008649b258dd> in run_experiment(X_train, X_test, y_train, y_test, batch_size, n_iter, n_init_points, base_model, semi_model)
    118                 sampler.fit(X_train[selected], y_train[selected])
    119 
--> 120                 new_selected = sampler.select_samples(X_train[~selected])
    121                 new_selected = new_selected.astype(int)
    122                 selected[index[~selected][new_selected]] = True
~/dss/code-envs/python/alssl/lib/python3.6/site-packages/cardinAL/base.py in select_samples(self, X, strategy)
     29 
     30     def select_samples(self, X, strategy='top'):
---> 31         sample_scores = self.score_samples(X)
     32         self.sample_scores_ = sample_scores
     33         if strategy == 'top':
~/dss/code-envs/python/alssl/lib/python3.6/site-packages/cardinAL/uncertainty.py in score_samples(self, X)
    175             predictions (np.array): Returns an array where selected samples are classified as 1.
    176         """
--> 177         return margin_score(self.classifier_, X)
    178 
    179 
~/dss/code-envs/python/alssl/lib/python3.6/site-packages/cardinAL/uncertainty.py in margin_score(classifier, X)
     45     """
     46     classwise_uncertainty = _get_probability_classes(classifier, X)
---> 47     part = np.partition(classwise_uncertainty, -2, axis=1)
     48     margin = 1 - (part[:, -1] - part[:, -2])
     49     return margin
<__array_function__ internals> in partition(*args, **kwargs)
~/dss/code-envs/python/alssl/lib/python3.6/site-packages/numpy/core/fromnumeric.py in partition(a, kth, axis, kind, order)
    744     else:
    745         a = asanyarray(a).copy(order="K")
--> 746     a.partition(kth, axis=axis, kind=kind, order=order)
    747     return a
    748 
ValueError: kth(=-1) out of bounds (1)

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