{"id":15906751,"url":"https://github.com/csinva/trees-to-networks","last_synced_at":"2026-04-12T11:35:34.669Z","repository":{"id":97069854,"uuid":"194323801","full_name":"csinva/trees-to-networks","owner":"csinva","description":"Bridging random forests and deep neural networks. Partial implementation of \"Neural Random Forests\" https://arxiv.org/abs/1604.07143","archived":false,"fork":false,"pushed_at":"2019-07-04T15:04:18.000Z","size":439,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-08T13:42:51.781Z","etag":null,"topics":["artificial-intelligence","classification","decision-tree","decision-tree-classifier","deep-learning","machine-learning","machinelearning","neural-network","neural-networks","paper-implementations","python","pytorch","random-forest","scikit-learn","statistics"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csinva.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-28T19:23:51.000Z","updated_at":"2023-11-06T14:45:39.000Z","dependencies_parsed_at":"2023-04-16T03:14:41.135Z","dependency_job_id":null,"html_url":"https://github.com/csinva/trees-to-networks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csinva%2Ftrees-to-networks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csinva%2Ftrees-to-networks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csinva%2Ftrees-to-networks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csinva%2Ftrees-to-networks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csinva","download_url":"https://codeload.github.com/csinva/trees-to-networks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246907896,"owners_count":20853157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","classification","decision-tree","decision-tree-classifier","deep-learning","machine-learning","machinelearning","neural-network","neural-networks","paper-implementations","python","pytorch","random-forest","scikit-learn","statistics"],"created_at":"2024-10-06T13:41:36.263Z","updated_at":"2026-04-12T11:35:34.634Z","avatar_url":"https://github.com/csinva.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Bridging trees and neural networks.\n**Code here converts sklearn tree -\u003e pytorch DNN**\n\n`rf_to_dnn_ex.ipynb` shows a simple example of converting a random forest to a DNN\n\nBoth random forests and DNNs are very strong predictive models. This [cool recent paper title \"Neural Random Forests\"](https://arxiv.org/pdf/1604.07143.pdf) gives a simple algorithm for exactly rewriting any random forest as a sparse neural network. This could be useful then for combining the inductive biases of both and other interesting things.\n\n## how does it work?\n\n![](biau_19_fig2.png)\n\nThe idea is to rewrite the neural network into 3 layers:\n\n1. The first layer identifies whether a point is on the left or right side of a split (outputs -1, 1)\n   - $out_{split} = \\text{sign}(in - thresh)$\n   - this can be made faster by doing indexing rather than a matrix multiply (maybe sparse tensor will be fast enough)\n2. The second layer determines whether a a point is in a leaf or not (ouputs 0/1)\n\t- $out_{leaf} = (\\sum w \\cdot in) ==  depth(leaf)$\n3. the final layer simply multiplies the vector of (0s/1s) by the value of the leaf\n  - $out_{pred} = \\sum_{leaf} out_{leaf} \\cdot val_{leaf}$\n  - the 0-1 helps make it sparser (and simpler :smile:)\n  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsinva%2Ftrees-to-networks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsinva%2Ftrees-to-networks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsinva%2Ftrees-to-networks/lists"}