Can anyone provide specific techniques with using ICD-10 codes in Machine Learning? I have usually used a simply approach of creating multiple binary column representing ICD-10 codes… which can get extremely long. Or I have used Hashing features. Are there other techniques or ways to use ICD-10 codes in ML? Anyone can provide a useful link to see various approaching to modeling such features?


Most machine learning around ICD codes deals with auto-encoding documents or NLP to extract ICD codes automatically from documents. Once you have them, most applications I have seen use them as is.

One simple alternative would be to assign the codes to relevant categories to reduce the number of levels and make them more interpretable. For example

  • injury types (e.g. F00–F99 for mental disorders)
  • body parts (e.g. S10-S19 & .. for neck injuries)
  • severity of injury etc.

depending on your application. Of course, if you don't want to define the categories beforehand, this can be done using some clustering or embedding method etc.


I've used ICD-10 codes using one-hot encoding / dummy variables as you describe in your Q. This creates a very sparse binary design matrix which has a large number of features as you say. Some ways I've used to make it more manageable RAM-wise: (Out of interest how long are your unique code columns, and number of row samples?)

  1. I find that by using parent codes (e.g. omitting the "." after the ICD codes: "G12.21" changes to "G12") there are fewer columns.

  2. As the design matrix is binary and very sparse, unless you are interested in the rare diagnoses, you can omit many co-morbidities depending on how rare the diagnoses are. e.g. discarding a few rare diagnosis for each patient (in my case with 200k rows, reduced columns from ~7,500 to ~6,500)


I was going to try this for codes of the form A12.3; Take the first letter, as a position in the alphabet, add 10 and then multiply by 10, giving you 26 values between 100 and 360 Append the second two digits to this number, i.e add 12 from the example above, to give 10012. Then append the final digit, i.e. 100123.

This should give you numerically comparable distances that you'd get from analysing the ICD10 codes as a tree, i.e. all codes that are near each other on one branch are numerically near each other on another branch, and shouldn't spill over too much. By that I mean that the numbers at the high end of one letter code shouldn't be nearer the lower numbers of another letter code than they are to other members of the group.

If anyone has any comments, I'd be interested?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.