{"id":15698637,"url":"https://github.com/nok/weka-porter","last_synced_at":"2025-05-09T01:48:16.098Z","repository":{"id":62588731,"uuid":"74912300","full_name":"nok/weka-porter","owner":"nok","description":"Transpile trained decision trees from Weka to C, Java or JavaScript.","archived":false,"fork":false,"pushed_at":"2022-12-26T20:26:16.000Z","size":29,"stargazers_count":7,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T01:48:10.561Z","etag":null,"topics":["data-science","machine-learning","weka"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nok.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-27T20:27:32.000Z","updated_at":"2024-12-13T19:32:05.000Z","dependencies_parsed_at":"2023-01-31T01:15:25.059Z","dependency_job_id":null,"html_url":"https://github.com/nok/weka-porter","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/nok%2Fweka-porter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nok%2Fweka-porter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nok%2Fweka-porter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nok%2Fweka-porter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nok","download_url":"https://codeload.github.com/nok/weka-porter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176440,"owners_count":21866142,"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":["data-science","machine-learning","weka"],"created_at":"2024-10-03T19:31:34.508Z","updated_at":"2025-05-09T01:48:16.073Z","avatar_url":"https://github.com/nok.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# weka-porter\n\n[![Build Status](https://img.shields.io/travis/nok/weka-porter/master.svg)](https://travis-ci.org/nok/weka-porter)\n[![PyPI](https://img.shields.io/pypi/v/weka-porter.svg)](https://pypi.python.org/pypi/weka-porter)\n[![PyPI](https://img.shields.io/pypi/pyversions/weka-porter.svg)](https://pypi.python.org/pypi/weka-porter)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nok/weka-porter/master/license.txt)\n\nTranspile trained decision trees from [Weka](http://www.cs.waikato.ac.nz/ml/weka/) to C, Java or JavaScript.\u003cbr\u003eIt's recommended for limited embedded systems and critical applications where performance matters most.\n\n\n## Benefit\n\nThe benefit of the module is to transpile a decision tree from the compact representation by the [Weka](http://www.cs.waikato.ac.nz/ml/weka/) software to a target programming language:\n\n```\noutlook = sunny\n|   humidity \u003c= 75: yes (2.0)\n|   humidity \u003e 75: no (3.0)\noutlook = overcast: yes (4.0)\noutlook = rainy\n|   windy = TRUE: no (2.0)\n|   windy = FALSE: yes (3.0)\n```\n\n```java\npublic static String classify(String outlook, boolean windy, double humidity) {\n    if (outlook.equals(\"sunny\")) {\n        if (humidity \u003c= 75) {\n            return \"yes\";\n        }\n        else if (humidity \u003e 75) {\n            return \"no\";\n        }\n    }\n    else if (outlook.equals(\"overcast\")) {\n        return \"yes\";\n    }\n    else if (outlook.equals(\"rainy\")) {\n        if (windy == true) {\n            return \"no\";\n        }\n        else if (windy == false) {\n            return \"yes\";\n        }\n    }\n    return null;\n}\n```\n\n\n## Installation\n\n```bash\npip install weka-porter\n```\n\n\n## Usage\n\nEither you use the porter as [imported module](#module) in your application or you use the [command-line interface](#cli).\n\n\n### Training\n\nFirst of all a trained decision tree is required.\n\n```\n# download Weka:\nwget https://netcologne.dl.sourceforge.net/project/weka/weka-3-8/3.8.2/weka-3-8-2.zip\nunzip weka-3-8-2.zip \u0026\u0026 cd weka-3-8-2\n\n# train decision tree and save the result:\njava -cp weka.jar weka.classifiers.trees.J48 -t data/weather.numeric.arff -v \u003e j48.txt\n```\n\nCopy and paste the compact representation from `j48.txt` to a new file (i.e. `j48_tree.txt`):\n\n```\noutlook = sunny\n|   humidity \u003c= 75: yes (2.0)\n|   humidity \u003e 75: no (3.0)\noutlook = overcast: yes (4.0)\noutlook = rainy\n|   windy = TRUE: no (2.0)\n|   windy = FALSE: yes (3.0)\n```\n\n\n### Module\n\nNow the saved decision tree can be ported to Java:\n\n```python\nfrom weka_porter import Porter\n\nporter = Porter(language='java')\noutput = porter.port('j48_tree.txt', method_name='classify')\n\nprint(output)\n```\n\nThe ported [decision tree](examples/basics.py#L12-L33) matches the [original version](examples/j48_tree.txt) of the estimator.\n\n\n### Command-line interface\n\nThis examples shows how you can port a estimator from the command line. The estimator can be ported by using the following command:\n\n```\npython -m weka_porter --input \u003ctxt_file\u003e [--output \u003cdestination_dir\u003e] [--c] [--java] [--js]\npython -m weka_porter -i \u003ctxt_file\u003e [-o \u003cdestination_dir\u003e] [--c] [--java] [--js]\n```\n\nThe target programming language is changeable on the fly:\n\n```bash\npython -m weka_porter -i j48_tree.txt --c\npython -m weka_porter -i j48_tree.txt --java\npython -m weka_porter -i j48_tree.txt --js\n```\n\nFinally the following command will display all options:\n\n```bash\npython -m weka_porter --help\npython -m weka_porter -h\n```\n\n\n## Development\n\n### Environment\n\nInstall the required environment [modules](environment.yml) by executing the script [environment.sh](scripts/environment.sh):\n\n```bash\nbash ./scripts/environment.sh\n```\n\n```bash\nconda env create -n weka-porter -f environment.yml\nsource activate weka-porter\n```\n\nFurthermore [Node.js](https://nodejs.org) (`\u003e=6`), [Java](https://java.com) (`\u003e=1.6`) and [GCC](https://gcc.gnu.org) (`\u003e=4.2`) are required for all tests.\n\n\n### Testing\n\nRun all [tests](tests) by executing the bash script [test.sh](scripts/test.sh):\n\n```bash\nbash ./scripts/test.sh\n```\n\n```bash\npython -m unittest discover -vp '*Test.py'\n```\n\nThe tests cover module functions as well as matching predictions of ported trees.\n\n\n## License\n\nThe library is Open Source Software released under the [MIT](license.txt) license.\n\n\n## Questions?\n\nDon't be shy and feel free to contact me on [Twitter](https://twitter.com/darius_morawiec).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnok%2Fweka-porter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnok%2Fweka-porter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnok%2Fweka-porter/lists"}