Package: pulearn
Positive-unlabeled learning with Python.Website:https://pulearn.github.io/pulearn/Documentation:https://pulearn.github.io/pulearn/doc/pulearn/frompulearnimportElkanotoPuClassifierfromsklearn.svmimportSVCsvc=SVC(C=10,kernel='rbf',gamma=0.4,probability=True)pu_estimator=ElkanotoPuClassifier(estimator=svc,hold_out_ratio=0.2)pu_estimator.fit(X,y)Contents1Documentation2Installation3Implemented Classifiers3.1Elkanoto3.1.1Classic Elkanoto3.1.2Weighted Elkanoto3.2Bagging-based PU-learning4Examples5Contributing5.1Installing for development5.2Running the tests5.3Adding tests5.4Code style5.5Adding documentation6License7Credits1DocumentationThis is the repository of thepulearnpackage, and this readme file is aimed to help potential contributors to the project.To learn more about how to usepulearn, eithervisit pulearn’s homepageor read theonline documentation of pulearn.2InstallationInstallpulearnwith:pipinstallpulearn3Implemented Classifiers3.1ElkanotoScikit-Learn wrappers for both the methods mentioned in the paper by Elkan and Noto,“Learning classifiers from only positive and unlabeled data”(published in Proceeding of the 14th ACM SIGKDD international conference on Knowledge discovery and data mining, ACM, 2008).These wrap the Python code froma fork by AdityaAS(with implementation to both methods) to theoriginal repositorybyAlexandre Drouinimplementing one of the methods.Unlabeled examples are expected to be indicated by-1, positives by1.3.1.1Classic ElkanotoTo use the classic (unweighted) method, use theElkanotoPuClassifierclass:frompulearnimportElkanotoPuClassifierfromsklearn.svmimportSVCsvc=SVC(C=10,kernel='rbf',gamma=0.4,probability=True)pu_estimator=ElkanotoPuClassifier(estimator=svc,hold_out_ratio=0.2)pu_estimator.fit(X,y)3.1.2Weighted ElkanotoTo use the weighted method, use theWeightedElkanotoPuClassifierclass:frompulearnimportWeightedElkanotoPuClassifierfromsklearn.svmimportSVCsvc=SVC(C=10,kernel='rbf',gamma=0.4,probability=True)pu_estimator=WeightedElkanotoPuClassifier(estimator=svc,labeled=10,unlabeled=20,hold_out_ratio=0.2)pu_estimator.fit(X,y)See the original paper for details on how thelabeledandunlabeledquantities are used to weigh training examples and affect the learning process:https://cseweb.ucsd.edu/~elkan/posonly.pdf.3.2Bagging-based PU-learningBased on the paperA bagging SVM to learn from positive and unlabeled examples (2013)by Mordelet and Vert. The implementation is byRoy Wright(roywrighton GitHub), and can be found inhis repository.Unlabeled examples are expected to be indicated by a number smaller than1, positives by1.frompulearnimportBaggingPuClassifierfromsklearn.svmimportSVCsvc=SVC(C=10,kernel='rbf',gamma=0.4,probability=True)pu_estimator=BaggingPuClassifier(base_estimator=svc,n_estimators=15)pu_estimator.fit(X,y)4ExamplesA nice code example of the classic Elkan-Noto classifier used for classification on theWisconsin breast cancer dataset, comparing it to a regular random forest classifer, can be found in theexamplesdirectory.To run it, clone the repository, and run the following command from the root of the repository, with a python environment wherepulearnis installed:pythonexamples/BreastCancerElkanotoExample.pyYou should see a nice plot, like the one below, comparing the F1 score of the PU learner versus a naive learner, demonstrating how PU learning becomes more effective - or worthwhile - the more positive examples are “hidden” from the training set.5ContributingPackage author and current maintainer is Shay Palachy (shay.palachy@gmail.com); You are more than welcome to approach him for help. Contributions are very welcomed, especially since this package is very much in its infancy and many other PU Learning methods can be added.5.1Installing for developmentClone:gitclonegit@github.com:pulearn/pulearn.gitInstall in development mode with test dependencies:cdpulearnpipinstall-e".[test]"5.2Running the testsTo run the tests, use:python-mpytestNoticepytestruns are configured by thepytest.inifile. Read it to understand the exactpytestarguments used.5.3Adding testsAt the time of writing,pulearnis maintained with a test coverage of 100%. Although challenging, I hope to maintain this status. If you add code to the package, please make sure you thoroughly test it. Codecov automatically reports changes in coverage on each PR, and so PR reducing test coverage will not be examined before that is fixed.Tests reside under thetestsdirectory in the root of the repository. Each model has a separate test folder, with each class - usually a pipeline stage - having a dedicated file (always starting with the string “test”) containing several tests (each a global function starting with the string “test”). Please adhere to this structure, and try to separate tests cases to different test functions; this allows us to quickly focus on problem areas and use cases. Thank you! :)5.4Code stylepulearncode is written to adhere to the coding style dictated byflake8. Practically, this means that one of the jobs that runs onthe project’s Travisfor each commit and pull request checks for a successfull run of theflake8CLI command in the repository’s root. Which means pull requests will be flagged red by the Travis bot if non-flake8-compliant code was added.To solve this, please runflake8on your code (whether through your text editor/IDE or using the command line) and fix all resulting errors. Thank you! :)5.5Adding documentationThis project is documented using thenumpy docstring conventions, which were chosen as they are perhaps the most widely-spread conventions that are both supported by common tools such as Sphinx and result in human-readable docstrings (in my personal opinion, of course). When documenting code you add to this project, please followthese conventions.Additionally, if you update thisREADME.rstfile,  usepython setup.py checkdocsto validate it compiles.6LicenseThis package is released as open-source software under theBSD 3-clause license. SeeLICENSE_NOTICE.mdfor the different copyright holders of different parts of the code.7CreditsImplementations code by:Elkan & Noto - Alexandre Drouin andAditraAS.Bagging PU Classifier -Roy Wright.Packaging, testing and documentation byShay Palachy.Fixes and feature contributions by:kjappelbaummeplandTEGELB