{"id":13484534,"url":"https://github.com/igrigorik/decisiontree","last_synced_at":"2025-05-14T21:04:58.658Z","repository":{"id":45450638,"uuid":"135191","full_name":"igrigorik/decisiontree","owner":"igrigorik","description":"ID3-based implementation of the ML Decision Tree algorithm","archived":false,"fork":false,"pushed_at":"2018-10-31T15:22:42.000Z","size":56,"stargazers_count":1445,"open_issues_count":10,"forks_count":129,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-04-15T01:56:59.907Z","etag":null,"topics":["decision-tree","machine-learning","ruby","rubyml"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/igrigorik.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}},"created_at":"2009-02-23T04:52:20.000Z","updated_at":"2025-04-09T13:55:57.000Z","dependencies_parsed_at":"2022-08-19T21:20:48.006Z","dependency_job_id":null,"html_url":"https://github.com/igrigorik/decisiontree","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fdecisiontree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fdecisiontree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fdecisiontree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fdecisiontree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igrigorik","download_url":"https://codeload.github.com/igrigorik/decisiontree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227606,"owners_count":22035669,"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":["decision-tree","machine-learning","ruby","rubyml"],"created_at":"2024-07-31T17:01:25.754Z","updated_at":"2025-05-14T21:04:58.609Z","avatar_url":"https://github.com/igrigorik.png","language":"Ruby","readme":"# Decision Tree\n\nA Ruby library which implements [ID3 (information gain)](https://en.wikipedia.org/wiki/ID3_algorithm) algorithm for decision tree learning. Currently, continuous and discrete datasets can be learned.\n\n- Discrete model assumes unique labels \u0026 can be graphed and converted into a png for visual analysis\n- Continuous looks at all possible values for a variable and iteratively chooses the best threshold between all possible assignments. This results in a binary tree which is partitioned by the threshold at every step. (e.g. temperate \u003e 20C)\n\n## Features\n- ID3 algorithms for continuous and discrete cases, with support for inconsistent datasets.\n- [Graphviz component](http://rockit.sourceforge.net/subprojects/graphr/) to visualize the learned tree \n- Support for multiple, and symbolic outputs and graphing of continuous trees.\n- Returns default value when no branches are suitable for input\n\n## Implementation\n\n- Ruleset is a class that trains an ID3Tree with 2/3 of the training data, converts it into set of rules and prunes the rules with the remaining 1/3 of the training data (in a [C4.5](https://en.wikipedia.org/wiki/C4.5_algorithm) way).\n- Bagging is a bagging-based trainer (quite obvious), which trains 10 Ruleset trainers and when predicting chooses the best output based on voting.\n\n[Blog post with explanation \u0026 examples](http://www.igvita.com/2007/04/16/decision-tree-learning-in-ruby/)\n\n## Example\n\n```ruby\nrequire 'decisiontree'\n\nattributes = ['Temperature']\ntraining = [\n  [36.6, 'healthy'],\n  [37, 'sick'],\n  [38, 'sick'],\n  [36.7, 'healthy'],\n  [40, 'sick'],\n  [50, 'really sick'],\n]\n\n# Instantiate the tree, and train it based on the data (set default to '1')\ndec_tree = DecisionTree::ID3Tree.new(attributes, training, 'sick', :continuous)\ndec_tree.train\n\ntest = [37, 'sick']\ndecision = dec_tree.predict(test)\nputs \"Predicted: #{decision} ... True decision: #{test.last}\"\n\n# =\u003e Predicted: sick ... True decision: sick\n\n# Specify type (\"discrete\" or \"continuous\") in the training data\nlabels = [\"hunger\", \"color\"]\ntraining = [\n        [8, \"red\", \"angry\"],\n        [6, \"red\", \"angry\"],\n        [7, \"red\", \"angry\"],\n        [7, \"blue\", \"not angry\"],\n        [2, \"red\", \"not angry\"],\n        [3, \"blue\", \"not angry\"],\n        [2, \"blue\", \"not angry\"],\n        [1, \"red\", \"not angry\"]\n]\n\ndec_tree = DecisionTree::ID3Tree.new(labels, training, \"not angry\", color: :discrete, hunger: :continuous)\ndec_tree.train\n\ntest = [7, \"red\", \"angry\"]\ndecision = dec_tree.predict(test)\nputs \"Predicted: #{decision} ... True decision: #{test.last}\"\n\n# =\u003e Predicted: angry ... True decision: angry\n```\n\n## License\n\nThe [MIT License](https://opensource.org/licenses/MIT) - Copyright (c) 2006 Ilya Grigorik\n","funding_links":[],"categories":["Scientific","Ruby","Machine Learning Libraries"],"sub_categories":["Text-to-Speech-to-Text","Decision trees"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrigorik%2Fdecisiontree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figrigorik%2Fdecisiontree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrigorik%2Fdecisiontree/lists"}