<commit_before># rankpruning

**rankpruning** is a python package for state-of-the-art binary classification with **partially mislabeled training examples**. This machine learning package implements the Rank Pruning algorithm and other methods for P̃Ñ learning (binary classification where some fraction of positive example labels are uniformly randomly flipped and some fraction of negative example labels are uniformly randomly flipped). Rank Pruning is theoretically grounded and trivial to use. The Rank Pruning algorithm ([<NAME>](http://www.curtisnorthcutt.com/), [<NAME>](http://cuaweb.mit.edu/Pages/Person/Page.aspx?PersonId=26273), & [<NAME>](http://feynman.mit.edu/ike/homepage/index.html), 2017) is under review at UAI 2017 as a submitted conference publication. A version of the paper is available on arXiv at this link: (coming soon in the next 5 days!). The `RankPruning()` class:
- works with any probabilistic classifer (e.g. neural network, logistic regression)
- is fast (time-efficient), taking about 2-3 times the training time of the classifier)
- also computes the fraction of noise in the positive and negative sets
- provides state-of-the-art (as of 2017) F1 score, AUC-PR, accuracy, etc. for binary classification with mislabeled training data (P̃Ñ learning).
- also works well when noise examples drawn from a third distribution are mixed into the training data.

We provide both Jupyter Notebook and python implementations of most files for portability and ease of use. A tutorial is also provided in the tutorial/tutorial.ipynb file. 

### Classification with Rank Pruning is easy

```python
rp = RankPruning(clf=logreg()) # or a CNN(), or NaiveBayes(), etc.
rp.fit(X, s)
pred = rp.predict(X)
``` 

It is trained with:
1. a feature matrix **X**
2. a vector **s** of binary (0 or 1) labels where an unknown fraction of labels may be mislabeled (flipped)
3. ANY probabilistic classifier **clf** as long as it has `clf.predict_proba()`, `clf.predict()`, and `clf.fit()` defined. 

Ideally, given training feature matrix **X** and noisy labels **s** (instead of the hidden, true labels **y**), fit **clf** as if you had called `clf.fit(X, y)` not `clf.fit(X, s)`, even though **y** is not available.#

### How does Rank Pruning work?

**rankpruning** is based on a joint research effort between the Massachusetts Institute of Technology's Department of Electrical Engineering and Computer Science, Office of Digital Learning, and Department of Physics. The Rank Pruning algorithm is theoretically grounded and trivial to use. **rankpruning** embodies the "learning with confident examples" paradigm and works as follows:
1. estimate the fraction of mislabeling in both the positive and negative sets
2. use these estimates to rank examples by confidence of being correctly labeled
3. prune out likely mislabeled data
4. train on the pruned set (an intended subset of the correctly labeled training data)   

### Installation

To use the **rankpruning** package, clone the repo and run:

```
$ cd rankpruning
$ pip install .
```

or if you plan to change any files, clone and run in developer mode:

```
$ cd rankpruning
$ pip install -e .
```

then in python, you can:

```
import rankpruning
from rankpruning import RankPruning
from rankpruning import other_pnlearning_methods<commit_msg>Added one line pip installation via github.<commit_after># rankpruning

**rankpruning** is a python package for state-of-the-art binary classification with **partially mislabeled training examples**. This machine learning package implements the Rank Pruning algorithm and other methods for P̃Ñ learning (binary classification where some fraction of positive example labels are uniformly randomly flipped and some fraction of negative example labels are uniformly randomly flipped). Rank Pruning is theoretically grounded and trivial to use. The Rank Pruning algorithm ([<NAME>](http://www.curtisnorthcutt.com/), [Tail<NAME>](http://cuaweb.mit.edu/Pages/Person/Page.aspx?PersonId=26273), & [<NAME>](http://feynman.mit.edu/ike/homepage/index.html), 2017) is under review at UAI 2017 as a submitted conference publication. A version of the paper is available on arXiv at this link: (coming soon in the next 5 days!). The `RankPruning()` class:
- works with any probabilistic classifer (e.g. neural network, logistic regression)
- is fast (time-efficient), taking about 2-3 times the training time of the classifier)
- also computes the fraction of noise in the positive and negative sets
- provides state-of-the-art (as of 2017) F1 score, AUC-PR, accuracy, etc. for binary classification with mislabeled training data (P̃Ñ learning).
- also works well when noise examples drawn from a third distribution are mixed into the training data.

We provide both Jupyter Notebook and python implementations of most files for portability and ease of use. A tutorial is also provided in the tutorial/tutorial.ipynb file. 

### Classification with Rank Pruning is easy

```python
rp = RankPruning(clf=logreg()) # or a CNN(), or NaiveBayes(), etc.
rp.fit(X, s)
pred = rp.predict(X)
``` 

It is trained with:
1. a feature matrix **X**
2. a vector **s** of binary (0 or 1) labels where an unknown fraction of labels may be mislabeled (flipped)
3. ANY probabilistic classifier **clf** as long as it has `clf.predict_proba()`, `clf.predict()`, and `clf.fit()` defined. 

Ideally, given training feature matrix **X** and noisy labels **s** (instead of the hidden, true labels **y**), fit **clf** as if you had called `clf.fit(X, y)` not `clf.fit(X, s)`, even though **y** is not available.#

### How does Rank Pruning work?

**rankpruning** is based on a joint research effort between the Massachusetts Institute of Technology's Department of Electrical Engineering and Computer Science, Office of Digital Learning, and Department of Physics. The Rank Pruning algorithm is theoretically grounded and trivial to use. **rankpruning** embodies the "learning with confident examples" paradigm and works as follows:
1. estimate the fraction of mislabeling in both the positive and negative sets
2. use these estimates to rank examples by confidence of being correctly labeled
3. prune out likely mislabeled data
4. train on the pruned set (an intended subset of the correctly labeled training data)   

### Installation

To use the **rankpruning** package just run:

```
$ pip install git+https://github.com/cgnorthcutt/rankpruning.git
```

If you'd like to explore the tutorial, test files, or make changes; clone the repo and run:

```
$ cd rankpruning
$ pip install -e .
```

then in python, you can:

```python
import rankpruning
from rankpruning import RankPruning
from rankpruning import other_pnlearning_methods
{'fraction_non_alphanumeric': 0.08693707127945124, 'fraction_numerical': 0.008947211452430659, 'mean_word_length': 4.852530541012216, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '157673', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1734, 'n_words': 911}