Thank you for your interest in ICD codex! I (Jeremy) wrote this in 2020 as part of class project and it has gotten quite a few downloads. However, since then, sequence representation has significantly improved. At this point, **I would not recommend using node2vec to represent ICD codes.** Instead, use a [language model](https://platform.openai.com/docs/guides/embeddings). The node2vec functionality is provided for compatibility with existing projects.
The `networkx` hierarchy should still remains useful.
If there is interest in extending this library for use with modern sequence learning algorithms, please reach out.
What is it?
A python library for building vector representations of ICD-9 and ICD-10 codes. (2025 comment: the vector representations here are constructed using outdated algorithms.) Because it takes advantage of the hierarchical nature of ICD codes, it also provides these hierarchies in a networkx format. (2025 comment: this data structure should still remain useful.)
Motivation
icdcodex was the first prize winner in the Data Driven Healthcare Track of John Hopkins' MedHacks 2020. It was hacked together to address the problem of ICD miscodes, which is a major issue for health insurance in the United States. Indeed, while ICD coding is tedious and labour intensive, it is not obvious how to automate because the output space is enourmous. For example, ICD-10 CM (clinical modification) has over 70,000 codes and growing.
There are many strategies for target encoding that address these issues. icdcodex has two features that make ICD classification more amenable to modeling:
- Access to a
networkxtree representation of the ICD-9 and ICD-10 hierarchies - Vector embeddings of ICD codes using the node2vec algorithm (including pre-computed embeddings and an interface to create new embeddings)
Example Code
from icdcodex import icd2vec, hierarchy
embedder = icd2vec.Icd2Vec(num_embedding_dimensions=64)
embedder.fit(*hierarchy.icd9())
X = get_patient_covariates()
y = embedder.to_vec(["0010"]) # Cholera due to vibrio cholerae
In this case, y is a 64-dimensional vector close to other Infectious And Parasitic Diseases codes.
Related Work
- node2vec Paper, Website, Code, Alternate Code
- Learning Low-Dimensional Representations of Medical Concepts: Paper, Code
The Hackathon Team
- Jeremy Fisher (Maintainer)
- Alhusain Abdalla
- Natasha Nehra
- Tejas Patel
- Hamrish Saravanakumar
Documentation
See the full documentation: https://icd-codex.readthedocs.io/en/latest/
Contributions
Contributions are always welcome!
History
0.5.2 (2025-01-05)
- Added 2025 ICD-10-CM
- Bumped deps
- Removed EOL python's from CI
- Fix bug where 2024 codes are being pulled from 2023
- Fixed some flake8 bugs
- Fixed use of deprecated field in networkx
0.4.9, 0.5.0 and 0.5.1 (2024-01-08)
- Added 2024 ICD-10-CM
- Fixed a bug where the node descriptions were being discarded
- Regenerated the hierarchy files with the descriptions
0.4.8 (2023-05-02)
- Use the newer scikit-learn PyPI location
- Deprecate the Python 3.6 version
- Add 2023 ICD-10-CM
0.4.6 (2022-10-13)
- Add 2022 ICD-10-CM (thank you @keithcallenberg!)
0.4.4 and 0.4.5 (2020-10-18)
- Add the code descriptions for ICD9
- Add usage on how to recapitulate functionality of sirrice/icd9
- Make the hierarchy directed to allow simpler and more intuitive traversal
- Fix issue where edges were not being formed between "Diseases Of The Blood And Blood-Forming Organs" and "Congenital Anomalies" and their children
0.4.3 (2020-10-04)
- Fix issue where hierarchy jsons were not being shipped with the pypi distribution
0.4.2 (2020-10-03)
- Add support for python <= 3.8 in the
hierarchymodule by using theimportlib.resourcesbackport
0.4.1 (2020-09-11)
- Update PyPI metadata
0.4.0 (2020-09-11)
- ICD-10-CM (2019 to 2020) codes are now fully present (whereas hackathon version missed certain codes)
- Versions of the ICD 9 and ICD-10-CM hierarchies are now cached to the
datamodule - Changed the hierarchy API:
hierarchy.icd9hierarchy()is nowhierarchy.icd9(). Ditto for ICD-10-CM.
0.3.0 (2020-09-05)
- Finesse API, now consistent between documentation and implementation
0.1.0 (2020-09-04)
- First release on PyPI, testing the waters during hackathon
Metadata
Release files for icdcodex 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| icdcodex-0.5.2.tar.gz | 29.7 MB | Without provenance | Details for icdcodex-0.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| icdcodex-0.5.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for icdcodex-0.5.2-py2.py3-none-any.whl |
Total release size: 36.4 MB
Release files / icdcodex-0.5.2.tar.gz
| Download URL | icdcodex-0.5.2.tar.gz |
|---|---|
| Size | 29.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5930ff8c04d1d4e970bfce87927ad03e6a19d078c949753ba4b9defbe3522171
|
|
BLAKE2b-256 checksum How to use checksums |
724d250db9de37f4b553132c87fb4b1e68c3989ed6369227679feac0c92403eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / icdcodex-0.5.2-py2.py3-none-any.whl
| Download URL | icdcodex-0.5.2-py2.py3-none-any.whl |
|---|---|
| Size | 6.7 MB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
db8a7c3c3902fe24508b65711ea3f38f08dc185c38ff0b66e213c60ad82a4e6b
|
|
BLAKE2b-256 checksum How to use checksums |
ae764eb30cdd85c50bf54a6931cddcb6c1136f53ef2669baba3c32325bb220d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for icdcodex 0.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.