{"id":21191790,"url":"https://github.com/edgeimpulse/example-custom-ml-block-sklearn-random-forest","last_synced_at":"2026-04-28T09:32:35.402Z","repository":{"id":225225508,"uuid":"753840569","full_name":"edgeimpulse/example-custom-ml-block-sklearn-random-forest","owner":"edgeimpulse","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-10T09:51:19.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-03T01:05:41.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause-clear","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edgeimpulse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-02-06T22:14:50.000Z","updated_at":"2025-02-10T09:51:22.000Z","dependencies_parsed_at":"2024-02-29T22:40:37.317Z","dependency_job_id":null,"html_url":"https://github.com/edgeimpulse/example-custom-ml-block-sklearn-random-forest","commit_stats":null,"previous_names":["edgeimpulse/example-custom-ml-block-sklearn-random-forest"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/edgeimpulse/example-custom-ml-block-sklearn-random-forest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edgeimpulse","download_url":"https://codeload.github.com/edgeimpulse/example-custom-ml-block-sklearn-random-forest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32375397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T09:24:15.638Z","status":"ssl_error","status_checked_at":"2026-04-28T09:24:15.071Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-20T19:05:18.837Z","updated_at":"2026-04-28T09:32:35.374Z","avatar_url":"https://github.com/edgeimpulse.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom scikit-learn Random Forest ML block examples for Edge Impulse\n\nThis repository is an example on how to [add a custom learning block](https://docs.edgeimpulse.com/docs/edge-impulse-studio/learning-blocks/adding-custom-learning-blocks) to Edge Impulse. This repository contains a Random Forest classifier and a Random Forest regression model built in scikit-learn.\n\nAs a primer, read the [Custom learning blocks](https://docs.edgeimpulse.com/docs/edge-impulse-studio/learning-blocks/adding-custom-learning-blocks) page in the Edge Impulse docs.\n\n## Running the pipeline\n\nYou run this pipeline via Docker. This encapsulates all dependencies and packages for you.\n\n### Running via Docker\n\n1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/).\n2. Install the [Edge Impulse CLI](https://docs.edgeimpulse.com/docs/edge-impulse-cli/cli-installation) v1.16.0 or higher.\n3. We need an Edge Impulse project with some data. Preferably create a new one and upload your own data, or alternatively:\n\n    **Classifier**\n\n    Clone a classification project, e.g. [Tutorial: continuous motion recognition](https://studio.edgeimpulse.com/public/14299/latest)\n\n    **Regression**\n\n    Clone a regression project, e.g. [Tutorial: temperature regression](https://studio.edgeimpulse.com/public/17972/latest)\n\n4. If you've created a new project, then under **Create impulse** add a processing block, and either a Classification or Regression block (depending on your data).\n5. Open a command prompt or terminal window.\n6. Initialize the block:\n\n    **Classifier**\n\n    ```\n    cd classifier\n    $ edge-impulse-blocks init\n    # Answer the questions:\n    # ? Choose a type of block: \"Machine learning block\"\n    # ? Choose an option: \"Create a new block\"\n    # ? Enter the name of your block: \"Random forest classifier\"\n    # ? What type of data does this model operate on? \"Classification\"\n    # ? Where can your model train? \"Both CPU or GPU (default)\"\n    ```\n\n    **Regression**\n\n    ```\n    cd regression\n    $ edge-impulse-blocks init\n    # Answer the questions:\n    # ? Choose a type of block: \"Machine learning block\"\n    # ? Choose an option: \"Create a new block\"\n    # ? Enter the name of your block: \"Random forest regression\"\n    # ? What type of data does this model operate on? \"Regression\"\n    # ? Where can your model train? \"Both CPU or GPU (default)\"\n    ```\n\n\n7. Fetch new data via:\n\n    ```\n    $ edge-impulse-blocks runner --download-data data/\n    ```\n\n8. Build the container:\n\n    **Classifier**\n\n    ```\n    $ cd classifier\n    $ docker build -t random-forest-classifier .\n    ```\n\n    **Regression**\n\n    ```\n    $ cd regression\n    $ docker build -t random-forest-regression .\n    ```\n\n9. Run the container to test the script (you don't need to rebuild the container if you make changes):\n\n    **Classifier**\n\n    ```\n    $ docker run --rm -v $PWD:/app random-forest-classifier --data-directory /app/data --out-directory /app/out --num-estimators 10\n    ```\n\n    **Regression**\n\n    ```\n    $ docker run --rm -v $PWD:/app random-forest-regression --data-directory /app/data --out-directory /app/out --num-estimators 10\n    ```\n\n10. This creates a `model.pkl` file in the out directory.\n\n#### Adding extra dependencies\n\nIf you have extra packages that you want to install within the container, add them to `requirements.txt` and rebuild the container.\n\n#### Adding new arguments\n\nTo add new arguments, see [Custom learning blocks \u003e Arguments to your script](https://docs.edgeimpulse.com/docs/edge-impulse-studio/learning-blocks/adding-custom-learning-blocks#arguments-to-your-script).\n\n## Fetching new data\n\nTo get up-to-date data from your project:\n\n1. Install the [Edge Impulse CLI](https://docs.edgeimpulse.com/docs/edge-impulse-cli/cli-installation) v1.16 or higher.\n2. Open a command prompt or terminal window.\n3. Fetch new data via:\n\n    ```\n    $ edge-impulse-blocks runner --download-data data/\n    ```\n\n## Pushing the block back to Edge Impulse\n\nYou can also push this block back to Edge Impulse, that makes it available like any other ML block so you can retrain your model when new data comes in, or deploy the model to device. See [Docs \u003e Adding custom learning blocks](https://docs.edgeimpulse.com/docs/edge-impulse-studio/organizations/adding-custom-transfer-learning-models) for more information.\n\n1. Push the block:\n\n    ```\n    $ edge-impulse-blocks push\n    ```\n\n2. The block is now available under any of your projects via **Create impulse \u003e Add new learning block**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedgeimpulse%2Fexample-custom-ml-block-sklearn-random-forest/lists"}