文件历史

36 次代码提交

作者 SHA1 备注 提交日期
Curtis G. Northcutt 1b813d9666 fix bug in hard-coded test. generalize the test (#448)
* fix bug in hard-coded test. generalize the test

* 🐛 cast rounded num_issues to int

np.rint outputs an array of the same shape and type as its input. num_label_issues is expected to return an integer.

Co-authored-by: Elías Snorrason <eliassno@gmail.com>
2022-09-15 18:16:56 -04:00
Curtis G. Northcutt 3ff8fab2d9 make num_label_issues = cj calibrated offdiag sum (#445)
The discrepancy occurs because cj calibrated maintains a guarantee that it will perfectly count every example in the dataset (assumes no out of distribution examples).

You can see this when by following this change of methods:

* see `calibrate_confident_joint`, specifically this line here: https://github.com/cleanlab/cleanlab/blob/master/cleanlab/count.py#L172
* round here https://github.com/cleanlab/cleanlab/blob/9240a8c56d020abec8566a0a56d22dcb99d32528/cleanlab/internal/util.py#L209
* the actual rounding occurs here https://github.com/cleanlab/cleanlab/blob/9240a8c56d020abec8566a0a56d22dcb99d32528/cleanlab/internal/util.py#L174

the fix to make `num_label_issues` the same is just to round instead of flooring.

see the two GREEN columns in the attached image

> [nit] consider `np.rint()` instead of `np.round()` for clarity

good call. updated
2022-09-15 11:44:27 -07:00
Jonas Mueller a4ad6460a2 Format return docstrings and add typing (#437)
* typing and return docstrings

* address typing complaints

* allow redefinition

* typing complains for pandas

* .values -> to_numpy()
2022-09-15 11:46:14 +00:00
Curtis G. Northcutt 3fb4133a5c np.array to np.ndarray 2022-08-09 03:30:57 -04:00
Curtis G. Northcutt 72d6c73a94 Clarify shapes of matrices in cj_multi_label 2022-08-09 03:25:03 -04:00
Ulyana c0fe76c098 Changed all docstring instances of np.array to np.ndarray (#336)
* Changed all instances of np.array in docstring to np.ndarray

* np.array is NOT a proper class name it is just a function to
  create np.ndarrays and therefore should not be parameter class

* Black formatting compliance
2022-08-08 23:30:12 -07:00
Jonas Mueller b93fdebf30 Add compatibility for tensorflow and pytorch Dataset objects (#311)
* validation_func docstring

* torch,tf compatibility+tests

* keras test

* skip tests if python < 3.7

* pytorch numpy int bug on windows

* make tensorflow test work on windows

* move tf env variable setting

* pytorch test increase epochs

* install cpu-tensorflow on windows CI

* torch test optimizer to adam

* fix bugs in shuffled TF dataset

* dummy unit test for TF on windows

* dummy code for TF windows testing

* deal with np.int bug on windows

* remove windows debugging code

* docstrings for new functionality

* address merge conflicts

* reformat after merge

* addressed comments
2022-07-27 21:42:13 -07:00
Hui Wen 6c6c13664e Standardize naming on K, num_classes and N, num_examples (#312)
* update N in classification.py

* minor docstring changes on K-1 classes

* use K in shape

* minor grammar fixes

* docs language improvements

Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
2022-07-18 18:50:17 -07:00
Jonas Mueller 9c543c6cba error for missing classes, consistency on determining num_classes, code cleanup (#308)
* edge cases

* unique_classes in get_confident_thresholds
2022-07-12 14:45:20 -07:00
Anish Athalye 0705ff2d0a Add static type checking
Our package doesn't have type annotations everywhere, so we can't use
mypy in strict mode just yet. Still, adding type checking in CI is
valuable, so we don't have unchecked annotations in our code.

This patch includes basic fixes to make type checking pass, including
switching the incorrect `np.array` type annotation for `np.ndarray` and
adding some assertions for flow-sensitive typing.
2022-07-06 17:21:56 -04:00
Hui Wen f62bc36e54 Allow CleanLearning to use validation data in each fold (#295)
* allow CleanLearning to use val data in each fold

* add unittest for using val data in CleanLearning
2022-06-28 22:04:22 -07:00
Jonas Mueller ffd6fc1b35 Make CleanLearning work with pandas and other non-numpy feature objects X (#285)
* cleanlearning w dfs

* work for sparse matrix as well

* simplify logic of labels_to_array and extend types

* address pr feedback

* add unit test

* rare label dataframe

* modularize subsetting code

* series rarelabel test

* replace cal.com with slack/email

* Add general method to find num_classes from labels

* compute num_classes with pred_probs.shape[1]

* fix broken commits, address 2nd round of comments

Co-authored-by: Curtis G. Northcutt <curtis.northcutt@gmail.com>
2022-06-24 04:01:55 -07:00
Curtis G. Northcutt af11106e77 Clarify labels format (#282)
Add clarification of the labels format requirements for all major API functions.

* Fix broken link

* Clarify reqs for labels format. rank.py does not yet support multi_label

* add double ticks to code in docstrings

* clarify docstring

* further clarify multi_label vs single label labels reqs

* also add new docstring to confident joint
2022-06-20 12:58:24 -07:00
Curtis G. Northcutt eb54447901 Change shape (N, ) back to (N,) to adhere to numpy standard 2022-06-20 11:10:00 -07:00
Curtis G. Northcutt 25036dc48e clarify expectation for labels 2022-06-20 10:32:28 -07:00
Curtis G. Northcutt 5bbea05992 Replace shape (N,) with (N, ) everywhere 2022-06-20 10:30:12 -07:00
Curtis G. Northcutt 1f40bdcd67 clarify all labels must be present in docstring 2022-06-19 16:00:51 -07:00
Curtis G. Northcutt 670d9d680e use shape[1] instead of unique everywhere. replace K with num_classes 2022-06-19 15:56:13 -07:00
Curtis G. Northcutt fc0db77892 remove unused code and unused param in docstring 2022-06-19 15:46:52 -07:00
Curtis G. Northcutt 215945f690 Remove redundant code. replace unique with pred_prob shape 1 2022-06-19 15:45:29 -07:00
Curtis G. Northcutt 7aa34a33ba Fix bug. get thresholds broken for multi_label 2022-05-20 21:55:32 -04:00
Curtis G. Northcutt e971350795 Clarify and fix several docstrings. (#214)
* Clarify and fix several docstrings.

* Adjustments based on Jonas's comments.

* fix typo
2022-04-15 19:06:45 -04:00
Curtis G. Northcutt 269a09d1b3 Fix error in docstring. missing item in tuple 2022-04-13 21:17:22 -07:00
Anish Athalye 5cf8f74232 Switch to pseudocode math over LaTeX math
In most cases, this looks nicer than the LaTeX math, and it's also more
readable in the terminal.
2022-04-09 08:47:46 -04:00
Anish Athalye aaa141ab7d Revise count 2022-04-09 08:41:08 -04:00
Anish Athalye 49b3717edc Make coarse-grained pass over docs
This patch fixes many of the egregious issues with docs rendering.
2022-04-09 07:33:24 -04:00
Curtis G. Northcutt 3a1f038e4d Add params to joint. link calibrate to joint. add type on docstring return 2022-04-08 13:01:53 -04:00
Jonas Mueller 423e5b0a07 Polish the APIs and file-structure to prepare for 2.0 release (#181)
* Makes some methods private that are not intended to be user-facing.
* Adds experimental module with fasttext.py and coteaching.py
* Adds header descriptions to code files which will render in docs
* Many miscellaneous fixes
2022-04-06 21:04:06 -07:00
Curtis G. Northcutt 2de67cbc34 Simple fix to Issue 158 (and potentially other issues) (#178)
* CleanLearning = Machine Learning with cleaned data

* Replace lnl instance naming with cl everywhere (CleanLearning)

* Add support for multi-class as well

* Add test based on #158

Co-authored-by: Anish Athalye <me@anishathalye.com>
2022-04-06 18:55:18 -04:00
Jonas Mueller d3eb08e75a added LearningWithNoisyLabels.find_label_issues instance method (#157)
* added LearningWithNoisyLabels.find_label_issues instance method

* LNL.find_label_issues no longer memoizes

* verbose unit test coverage

* Fixed all issues in PR. Fixed confident joint usage in LNL.find_label_issues. Fixed other minor bugs. Added tests

Co-authored-by: Curtis G. Northcutt <curtis.northcutt@gmail.com>
Co-authored-by: Anish Athalye <me@anishathalye.com>
2022-04-06 12:24:27 -04:00
Jonas Mueller 1247f165f2 Improve user-control (#149)
* improved language in docs Quickstart

* LearningWithNoisyLabels refactor to improve API flexibility and UX

* fix LearningWithNoisy rare label handling

* additional arg-checking unit tests
2022-03-30 08:18:38 -07:00
Anish Athalye 1848db0223 Fix sklearn estimator cloning
Arbitrary scikit-learn estimators are not safe to clone via
`copy.deepcopy()`, for example when they contain state that cannot be
pickled, such as a Keras model that contains a `_thread.RLock` [1]. The
correct way to clone an estimator is to use `sklearn.base.clone()` [2],
which constructs a new unfitted estimator with the same parameters as
the original by calling `get_params()` followed by creating a new object
of the class, passing the parameters to `__init__()`. This patch
switches from `copy.deepcopy` to `sklearn.base.clone`.

This patch also updates the MNIST PyTorch CNN example model to be
compatible with `sklearn.base.clone`. Writing a custom `get_params`
implementation usually wouldn't be necessary with a more standard
estimator that inherits from `BaseEstimator`, but it was necessary to
override the method in this case because of the nonstandard
implementation that supports multiple datasets and does data loading
within the estimator itself based on the `dataset` argument.

[1]: https://github.com/cleanlab/cleanlab/issues/87
[2]: https://scikit-learn.org/stable/modules/generated/sklearn.base.clone.html
2022-03-28 15:54:19 -04:00
Jonas Mueller 7b2340b638 Utilites -> internal submodule refactor (#141)
* utilities -> internals

* docbuilding instructions improvement

* fixup formatting of contributing.md

* change contributor guidelines language to be optional

* line formatting
2022-03-28 09:53:10 -07:00
Johnson Kuan c50836cfbf Add label quality scoring functions and user API to choose the method (#131)
* Add label quality scoring function for users to choose the scoring method.

Add confidence_weighted_entropy as another label quality score that is available for scoring and ranking.

Add option in scoring function to adjust predicted probabilities by subtracting the class thresholds.

Refactor order_label_issues to use the new label quality scoring function and accept keyword args.

* Cleanup docstring in label quality scoring functions

* Change rank_by_kwargs default to empty dict. Dict is used as keyword args for label quality scoring function.

* Cleanup docstrings. Add **rank_by_kwargs to signature of order_label_issues function.

* Add exception handler for invalid rank_by methods

* Add **rank_by_kwargs to allow keyword args in find_label_issues()

* Add test for confidence_weighted_entropy rank scoring function

* Add test for scoring function that accepts scoring method

* Cleanup comments

* Update test for scoring functions

* Update test for scoring functions

* Modify order_label_issues() function to run score_label_quality with (labels, pred_probs) and then filter with label_issues_mask. This is more robust to allow us to adjust the pred_probs (e.g. subtract confident class thresholds)

* Update test for label quality scoring

* Update test for label quality scoring

* Update exception handler for label scoring function

* Add test for subtracting confident class thresholds

* Update test for subtracting confident class thresholds

* Update test for subtracting confident class thresholds

* Add ensemble label quality scoring function

* Update test for ensemble label quality scoring function

* Update test for ensemble label quality scoring function

* Update docstrings for functions that accept adj_pred_probs with description of the adjustment to pred_probs

* Update find_label_issues to pass rank_by_kwargs as a dict

* Cleanup comments

* Refactor tests for scoring functions to avoid redundancies

* Refactor tests for scoring functions to avoid redundancies. Use parameterize instead of for-loop

* Parameterize scoring method to test ensemble scoring function

* Print scoring method when scoring function test fails

* Cleanup docstrings to avoid redundancies

* Move class confident threshold functions to new label quality utils module. Add weight_ensemble_members_by parameter to label quality ensemble scoring function allows users to choose weighting scheme (uniform, accuracy). Enhance tests for CI.

* Add test for CI. Test bad arg for weight_ensemble_members_by parameter.

* Add explicit error checking of pred_probs_list arg.

* Cleanup docstring and print statements

* Cleanup docstrings. Move get_entropy to utils. Refactor score_label_quality_ensemble to print accuracy weights

* Change default label quality scoring method to normalized_margin. Add to docstring explaining when to use normalized_margin vs self_confidence.

* Cleanup docstring

* Cleanup docstrings. Rename get_entropy() to get_normalized_entropy()

* Rename score_label_quality() to get_label_quality_scores(). Rename score_label_quality_ensemble() to get_label_quality_ensemble_scores().

* Remove extra indent in docstring

* Rename adj_pred_probs to adjust_pred_probs. Move get_confident_thresholds() to count.py module.

* Add comment to explain why we add a dimension for numpy broadcasting.

* Change renormalization logic when adjusting pred_probs. Raise ValueError when adjust_pred_probs is used with unsupported scoring method. Add test for ValueError.

* Update tests to account for unsupported method when running adjust_pred_probs.

* Enhance docstring tests
2022-03-26 18:50:34 -07:00
Anish Athalye 11dff1faf4 Standardize code style to Black (#107)
* Set up Black as the code style

* Migrate code style to Black
2022-03-16 21:27:36 -04:00
Curtis G. Northcutt 8f9f3f5380 Major API change. Introducing Cleanlab 2.0 (#128)
* Refactor modules pruning to filter and latent_estimation to count

* Remove polyplex (research) algorithms from cleanlab

* Create new module rank and move scoring functions to rank.

* Rename test to match new module names

* Fixed error in normalized margin. added ranking for arbitrary psx and labels.

* Remove unused tests and methods. add multi-label support for baseline.

* Move baseline methods to filter and delete baseline module.

* change filter.get_noise_indices to filter.find_label_issues

* Rename baseline methods. fill out docstrings.

* Only require 1 example to be left in each class after removing errors. (instead of 5)

* Remove K as a parameter to count.compute_confident_joint

* Add C_argmax and C_ij methods from CL paper to find_label_issues

* Add warnings for new prune methods and frac_noise. Fix tests.

* Add baseline tests to test_rank_filter and delete baseline test

* Remove inverse_noise_matrix parameter in classification call to find_label_issues

* add todo to update docstring with new ranking functions

* 100% tests pass. add multi-label support for prune_method

* Major NOT-backwards-compatible name changes to most components

* More Major NOT-backwards-compatible name changes

* fixed s -> label mistakes

* Several nomenclature updates from PR feedback. models renamed to example models.

* Remove python2 support across all modules.

* major api changes. psx -> pred_probs. prob_given_label -> self_confidence. testing added.

* enable python version 3.9 for pytorch model.

* ran spellcheck

* ran grammar check

* Update count.py

* Update filter.py

* Update setup.py and ci.yml to no longer support Python 2 and py3.4/5

* Increase test coverage and documentation of rank module methods.

* create utils submodule and move util and latent_algebra

* Rename y everywhere to true_labels, and p(true_label=..)

* Enforce positional arguments in methods. Fully remove py2 support.
2022-03-16 06:52:03 -04:00