{"id":18923999,"url":"https://github.com/crflynn/skranger","last_synced_at":"2025-08-21T20:33:38.731Z","repository":{"id":38961040,"uuid":"261603270","full_name":"crflynn/skranger","owner":"crflynn","description":"scikit-learn compatible Python bindings for ranger C++ random forest library","archived":false,"fork":false,"pushed_at":"2023-06-02T18:15:31.000Z","size":651,"stargazers_count":52,"open_issues_count":10,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-19T19:30:58.531Z","etag":null,"topics":["machine-learning","random-forest","scikit-learn"],"latest_commit_sha":null,"homepage":"https://skranger.readthedocs.io/en/stable/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crflynn.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-05T23:13:13.000Z","updated_at":"2024-11-05T01:19:21.000Z","dependencies_parsed_at":"2023-01-25T05:31:13.658Z","dependency_job_id":"b1226153-c235-4ee8-b278-ebc5a06f1ad7","html_url":"https://github.com/crflynn/skranger","commit_stats":{"total_commits":110,"total_committers":5,"mean_commits":22.0,"dds":0.08181818181818179,"last_synced_commit":"2467f43f118177c68e3eba4100aa6d3c6eee5ba6"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crflynn%2Fskranger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crflynn%2Fskranger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crflynn%2Fskranger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crflynn%2Fskranger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crflynn","download_url":"https://codeload.github.com/crflynn/skranger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230532451,"owners_count":18240792,"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":["machine-learning","random-forest","scikit-learn"],"created_at":"2024-11-08T11:05:13.941Z","updated_at":"2024-12-20T04:08:25.135Z","avatar_url":"https://github.com/crflynn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"skranger\n========\n\n|build| |wheels| |rtd| |pypi| |pyversions|\n\n.. |build| image:: https://github.com/crflynn/skranger/actions/workflows/build_and_test.yml/badge.svg\n    :target: https://github.com/crflynn/skranger/actions\n\n.. |wheels| image:: https://github.com/crflynn/skranger/actions/workflows/release.yml/badge.svg\n    :target: https://github.com/crflynn/skranger/actions\n\n.. |rtd| image:: https://img.shields.io/readthedocs/skranger.svg\n    :target: http://skranger.readthedocs.io/en/latest/\n\n.. |pypi| image:: https://img.shields.io/pypi/v/skranger.svg\n    :target: https://pypi.python.org/pypi/skranger\n\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/skranger.svg\n    :target: https://pypi.python.org/pypi/skranger\n\n``skranger`` provides `scikit-learn \u003chttps://scikit-learn.org/stable/index.html\u003e`__ compatible Python bindings to the C++ random forest implementation, `ranger \u003chttps://github.com/imbs-hl/ranger\u003e`__, using `Cython \u003chttps://cython.readthedocs.io/en/latest/\u003e`__.\n\nThe latest release of ``skranger`` uses version `0.12.1 \u003chttps://github.com/imbs-hl/ranger/releases/tag/0.12.1\u003e`__ of ``ranger``.\n\n\nInstallation\n------------\n\n``skranger`` is available on `pypi \u003chttps://pypi.org/project/skranger\u003e`__ and can be installed via pip:\n\n.. code-block:: bash\n\n    pip install skranger\n\n\nUsage\n-----\n\nThere are two ``sklearn`` compatible classes, ``RangerForestClassifier`` and ``RangerForestRegressor``. There is also the ``RangerForestSurvival`` class, which aims to be compatible with the `scikit-survival \u003chttps://github.com/sebp/scikit-survival\u003e`__ API.\n\n\nRangerForestClassifier\n~~~~~~~~~~~~~~~~~~~~~~\n\nThe ``RangerForestClassifier`` predictor uses ``ranger``'s ForestProbability class to enable both ``predict`` and ``predict_proba`` methods.\n\n.. code-block:: python\n\n    from sklearn.datasets import load_iris\n    from sklearn.model_selection import train_test_split\n    from skranger.ensemble import RangerForestClassifier\n\n    X, y = load_iris(return_X_y=True)\n    X_train, X_test, y_train, y_test = train_test_split(X, y)\n\n    rfc = RangerForestClassifier()\n    rfc.fit(X_train, y_train)\n\n    predictions = rfc.predict(X_test)\n    print(predictions)\n    # [1 2 0 0 0 0 1 2 1 1 2 2 2 1 1 0 1 1 0 1 1 1 0 2 1 0 0 1 2 2 0 1 2 2 0 2 0 0]\n\n    probabilities = rfc.predict_proba(X_test)\n    print(probabilities)\n    # [[0.01333333 0.98666667 0.        ]\n    #  [0.         0.         1.        ]\n    #  ...\n    #  [0.98746032 0.01253968 0.        ]\n    #  [0.99       0.01       0.        ]]\n\n\nRangerForestRegressor\n~~~~~~~~~~~~~~~~~~~~~\n\nThe ``RangerForestRegressor`` predictor uses ``ranger``'s ForestRegression class. It also supports quantile regression using the ``predict_quantiles`` method.\n\n.. code-block:: python\n\n    from sklearn.datasets import load_boston\n    from sklearn.model_selection import train_test_split\n    from skranger.ensemble import RangerForestRegressor\n\n    X, y = load_boston(return_X_y=True)\n    X_train, X_test, y_train, y_test = train_test_split(X, y)\n\n    rfr = RangerForestRegressor()\n    rfr.fit(X_train, y_train)\n\n    predictions = rfr.predict(X_test)\n    print(predictions)\n    # [26.27401667  8.96549989 24.82981667 27.92506667 28.04606667 45.4693\n    #  21.89681787 40.30345    11.53959613 19.13675    15.88567273 16.69713567\n    #  ...\n    #  20.29025364 26.21245833 23.79643333 14.03546362 21.24893333 34.8825\n    #  21.22463333]\n\n    # enable quantile regression on instantiation\n    rfr = RangerForestRegressor(quantiles=True)\n    rfr.fit(X_train, y_train)\n\n    quantile_lower = rfr.predict_quantiles(X_test, quantiles=[0.1])\n    print(quantile_lower)\n    # [22.    5.   21.88 23.08 23.1  35.89 10.85 31.5   7.04 14.5  11.7  10.9\n    #   8.1  28.38  7.2  19.6  29.1  13.1  24.94 21.09 15.6  11.7  10.41 14.5\n    #  ...\n    #  18.9  21.4   9.43  8.7  26.46 18.99  7.2  19.27 18.5  21.19 18.99 18.88\n    #  14.07 21.87 22.18  9.43 17.28 29.6  18.2 ]\n    quantile_upper = rfr.predict_quantiles(X_test, quantiles=[0.9])\n    print(quantile_upper)\n    # [30.83 12.85 29.01 33.1  33.1  50.   29.75 50.   15.   23.   19.96 21.4\n    #  20.53 50.   13.35 25.   48.5  19.6  46.   26.6  23.7  20.1  17.8  21.4\n    #  ...\n    #  26.78 28.1  17.86 27.5  46.25 24.4  16.74 24.4  28.7  29.1  24.4  25.\n    #  25.   31.51 28.   20.8  26.7  42.13 24.24]\n\n\nRangerForestSurvival\n~~~~~~~~~~~~~~~~~~~~\n\nThe ``RangerForestSurvival`` predictor uses ``ranger``'s ForestSurvival class, and has an interface similar to the RandomSurvivalForest found in the ``scikit-survival`` package.\n\n.. code-block:: python\n\n    from sksurv.datasets import load_veterans_lung_cancer\n    from sklearn.model_selection import train_test_split\n    from skranger.ensemble import RangerForestSurvival\n\n    X, y = load_veterans_lung_cancer()\n    # select the numeric columns as features\n    X = X[[\"Age_in_years\", \"Karnofsky_score\", \"Months_from_Diagnosis\"]]\n    X_train, X_test, y_train, y_test = train_test_split(X, y)\n\n    rfs = RangerForestSurvival()\n    rfs.fit(X_train, y_train)\n\n    predictions = rfs.predict(X_test)\n    print(predictions)\n    # [107.99634921  47.41235714  88.39933333  91.23566667  61.82104762\n    #   61.15052381  90.29888492  47.88706349  21.25111508  85.5768254\n    #   ...\n    #   56.85498016  53.98227381  48.88464683  95.58649206  48.9142619\n    #   57.68516667  71.96549206 101.79123016  58.95402381  98.36299206]\n\n    chf = rfs.predict_cumulative_hazard_function(X_test)\n    print(chf)\n    # [[0.04233333 0.0605     0.24305556 ... 1.6216627  1.6216627  1.6216627 ]\n    #  [0.00583333 0.00583333 0.00583333 ... 1.55410714 1.56410714 1.58410714]\n    #  ...\n    #  [0.12933333 0.14766667 0.14766667 ... 1.64342857 1.64342857 1.65342857]\n    #  [0.00983333 0.0112619  0.04815079 ... 1.79304365 1.79304365 1.79304365]]\n\n    survival = rfs.predict_survival_function(X_test)\n    print(survival)\n    # [[0.95855021 0.94129377 0.78422794 ... 0.19756993 0.19756993 0.19756993]\n    #  [0.99418365 0.99418365 0.99418365 ... 0.21137803 0.20927478 0.20513086]\n    #  ...\n    #  [0.87868102 0.86271864 0.86271864 ... 0.19331611 0.19331611 0.19139258]\n    #  [0.99021486 0.98880127 0.95299007 ... 0.16645277 0.16645277 0.16645277]]\n\n\nLicense\n-------\n\n``skranger`` is licensed under `GPLv3 \u003chttps://github.com/crflynn/skranger/blob/master/LICENSE.txt\u003e`__.\n\nDevelopment\n-----------\n\nTo develop locally, it is recommended to have ``asdf``, ``make`` and a C++ compiler already installed. After cloning, run ``make setup``. This will setup the ranger submodule, install python and poetry from ``.tool-versions``, install dependencies using poetry, copy the ranger source code into skranger, and then build and install skranger in the local virtualenv.\n\nTo format code, run ``make fmt``. This will run isort and black against the .py files.\n\nTo run tests and inspect coverage, run ``make test``.\n\nTo rebuild in place after making changes, run ``make build``.\n\nTo create python package artifacts, run ``make dist``.\n\nTo build and view documentation, run ``make docs``.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrflynn%2Fskranger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrflynn%2Fskranger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrflynn%2Fskranger/lists"}