-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for empty levels #minor (#37)
* Add support for empty levels * Refactor predict method for local classifier per parent node * Refactor predict() method for local classifier per level * Add black linting and badge
- Loading branch information
Showing
19 changed files
with
568 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
HiClass is an open-source Python library for hierarchical classification compatible with scikit-learn. | ||
|
||
[](https://github.com/mirand863/hiclass/actions/workflows/deploy-pypi.yml) [](https://hiclass.readthedocs.io/en/latest/?badge=latest) [](https://codecov.io/gh/mirand863/hiclass) [](https://pypi.org/project/hiclass/) [](https://anaconda.org/conda-forge/hiclass) [](https://opensource.org/licenses/BSD-3-Clause) | ||
[](https://github.com/mirand863/hiclass/actions/workflows/deploy-pypi.yml) [](https://hiclass.readthedocs.io/en/latest/?badge=latest) [](https://codecov.io/gh/mirand863/hiclass) [](https://pypi.org/project/hiclass/) [](https://anaconda.org/conda-forge/hiclass) [](https://opensource.org/licenses/BSD-3-Clause) [](https://github.com/psf/black) | ||
|
||
✨ Here is a **demo** that shows HiClass in action on hierarchical data: | ||
|
||
|
@@ -16,7 +16,7 @@ HiClass is an open-source Python library for hierarchical classification compati | |
- [Who is using HiClass?](#who-is-using-hiclass) | ||
- [Install](#install) | ||
- [Quick start](#quick-start) | ||
- [Step-by-step- walk-through](#step-by-step-walk-through) | ||
- [Step-by-step walk-through](#step-by-step-walk-through) | ||
- [API documentation](#api-documentation) | ||
- [FAQ](#faq) | ||
- [Support](#support) | ||
|
@@ -34,7 +34,7 @@ HiClass is an open-source Python library for hierarchical classification compati | |
- **Hierarchical metrics:** HiClass supports the computation of hierarchical precision, recall and f-score, which are more appropriate for hierarchical data than traditional metrics. | ||
- **Compatible with pickle:** Easily store trained models on disk for future use. | ||
|
||
**Don't see a feature on this list?** Search our [issue tracker](https://github.com/mirand863/hiclass/issues) if someone has already requested it and add a comment to it explaining your use-case, or open a new issue if not. We prioritize our roadmap based on user feedback, so we'd love to hear from you. | ||
**Any feature missing on this list?** Search our [issue tracker](https://github.com/mirand863/hiclass/issues) to see if someone has already requested it and add a comment to it explaining your use-case. Otherwise, please open a new issue describing the requested feature and possible use-case scenario. We prioritize our roadmap based on user feedback, so we would love to hear from you. | ||
|
||
## Benchmarks | ||
|
||
|
@@ -85,7 +85,7 @@ We would love to benchmark with larger datasets, if we can find them in the publ | |
|
||
Here is our public roadmap: https://github.com/mirand863/hiclass/projects/1. | ||
|
||
We do Just-In-Time planning, and we tend to reprioritize based on your feedback. Hence, items you see on this roadmap are subject to change. We prioritize features based on the number of people asking for it, features/fixes that are small enough and can be addressed while we work on other related features, features/fixes that help improve stability & relevance and features that address interesting use cases that excite us! If you'd like to have a request prioritized, we ask that you add a detailed use-case for it, either as a comment on an existing issue (besides a thumbs-up) or in a new issue. The detailed context helps. | ||
We do Just-In-Time planning, and we tend to reprioritize based on your feedback. Hence, items you see on this roadmap are subject to change. We prioritize features based on the number of people asking for it, features/fixes that are small enough and can be addressed while we work on other related features, features/fixes that help improve stability & relevance and features that address interesting use cases that excite us! If you would like to have a request prioritized, we ask that you add a detailed use-case for it, either as a comment on an existing issue (besides a thumbs-up) or in a new issue. The detailed context helps. | ||
|
||
|
||
## Who is using HiClass? | ||
|
@@ -123,7 +123,7 @@ Here's a quick example showcasing how you can train and predict using a local cl | |
from hiclass import LocalClassifierPerNode | ||
from sklearn.ensemble import RandomForestClassifier | ||
|
||
# define data | ||
# Define data | ||
X_train = [[1], [2], [3], [4]] | ||
X_test = [[4], [3], [2], [1]] | ||
Y_train = [ | ||
|
@@ -152,7 +152,7 @@ from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer | |
from sklearn.linear_model import LogisticRegression | ||
from sklearn.pipeline import Pipeline | ||
|
||
# define data | ||
# Define data | ||
X_train = [ | ||
'Struggling to repay loan', | ||
'Unable to get annual report', | ||
|
@@ -220,7 +220,9 @@ Please reach out to [email protected]. | |
|
||
## Contributing | ||
|
||
We are a small team on a mission to democratize hierarchical classification, and we'll take all the help we can get! If you'd like to get involved, here's information on [contribution guidelines and how to test the code locally](https://github.com/mirand863/hiclass/blob/main/CONTRIBUTING.md). | ||
We are a small team on a mission to democratize hierarchical classification, and we will take all the help we can get! If you would like to get involved, here is information on [contribution guidelines and how to test the code locally](https://github.com/mirand863/hiclass/blob/main/CONTRIBUTING.md). | ||
|
||
You can contribute in multiple ways, e.g., reporting bugs, writing or translating documentation, reviewing or refactoring code, requesting or implementing new features, etc. | ||
|
||
## Getting the latest updates | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
Gallery of Examples | ||
=================== | ||
|
||
These examples illustrate the main features of HiClass. | ||
These examples illustrate the main features of HiClass. | ||
|
||
.. toctree:: | ||
:hidden: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
========================== | ||
Different Number of Levels | ||
========================== | ||
HiClass supports different number of levels in the hierarchy. | ||
For this example, we will train a local classifier per node | ||
with a hierarchy similar to the following image: | ||
.. figure:: ../algorithms/local_classifier_per_node.svg | ||
:align: center | ||
""" | ||
from sklearn.linear_model import LogisticRegression | ||
|
||
from hiclass import LocalClassifierPerNode | ||
|
||
# Define data | ||
X_train = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] | ||
X_test = [[9, 10], [7, 8], [5, 6], [3, 4], [1, 2]] | ||
Y_train = [ | ||
["Bird"], | ||
["Reptile", "Snake"], | ||
["Reptile", "Lizard"], | ||
["Mammal", "Cat"], | ||
["Mammal", "Wolf", "Dog"], | ||
] | ||
|
||
# Use random forest classifiers for every node | ||
rf = LogisticRegression() | ||
classifier = LocalClassifierPerNode(local_classifier=rf) | ||
|
||
# Train local classifier per node | ||
classifier.fit(X_train, Y_train) | ||
|
||
# Predict | ||
predictions = classifier.predict(X_test) | ||
print(predictions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.