{"id":13578713,"url":"https://github.com/trent-b/iterative-stratification","last_synced_at":"2025-05-15T03:08:42.072Z","repository":{"id":29269753,"uuid":"120142477","full_name":"trent-b/iterative-stratification","owner":"trent-b","description":"scikit-learn cross validators for iterative stratification of multilabel data","archived":false,"fork":false,"pushed_at":"2024-10-12T16:36:02.000Z","size":47,"stargazers_count":864,"open_issues_count":2,"forks_count":74,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-12T06:04:39.966Z","etag":null,"topics":["cross-validation","multilabel","multilabel-classification","scikit-learn","stratification"],"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","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trent-b.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}},"created_at":"2018-02-04T00:32:10.000Z","updated_at":"2025-05-09T12:02:47.000Z","dependencies_parsed_at":"2024-12-04T20:11:09.899Z","dependency_job_id":"6c3f7137-2532-4435-94c3-7dd6d2c5f2c7","html_url":"https://github.com/trent-b/iterative-stratification","commit_stats":{"total_commits":51,"total_committers":8,"mean_commits":6.375,"dds":"0.27450980392156865","last_synced_commit":"6517468892a8c4956b9b5e4844c33adca4f1aeb9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trent-b%2Fiterative-stratification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trent-b%2Fiterative-stratification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trent-b%2Fiterative-stratification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trent-b%2Fiterative-stratification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trent-b","download_url":"https://codeload.github.com/trent-b/iterative-stratification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264771,"owners_count":22041794,"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":["cross-validation","multilabel","multilabel-classification","scikit-learn","stratification"],"created_at":"2024-08-01T15:01:33.117Z","updated_at":"2025-05-15T03:08:37.039Z","avatar_url":"https://github.com/trent-b.png","language":"Python","funding_links":[],"categories":["Python","其他_机器学习与深度学习","Sklearn实用程序"],"sub_categories":[],"readme":"\n[![Build Status](https://travis-ci.org/vfdev-5/iterative-stratification.svg?branch=master)](https://travis-ci.org/vfdev-5/iterative-stratification)\n[![Coverage Status](https://coveralls.io/repos/github/vfdev-5/iterative-stratification/badge.svg?branch=master)](https://coveralls.io/github/vfdev-5/iterative-stratification?branch=master)\n\n# iterative-stratification\niterative-stratification is a project that provides [scikit-learn](http://scikit-learn.org/) compatible cross validators with stratification for multilabel data.\n\nPresently scikit-learn provides several cross validators with stratification. However, these cross validators do not offer the ability to stratify _multilabel_ data. This iterative-stratification project offers implementations of MultilabelStratifiedKFold, MultilabelRepeatedStratifiedKFold, and MultilabelStratifiedShuffleSplit with a base algorithm for stratifying multilabel data described in the following paper:\n\nSechidis K., Tsoumakas G., Vlahavas I. (2011) On the Stratification of Multi-Label Data. In: Gunopulos D., Hofmann T., Malerba D., Vazirgiannis M. (eds) Machine Learning and Knowledge Discovery in Databases. ECML PKDD 2011. Lecture Notes in Computer Science, vol 6913. Springer, Berlin, Heidelberg.\n\n## Requirements\niterative-stratification has been tested under Python 3.4 through 3.9 with the following dependencies:\n- scipy(\u003e=0.13.3)\n- numpy(\u003e=1.8.2)\n- scikit-learn(\u003e=0.19.0)\n\n## Installation\niterative-stratification is currently available on the PyPi repository and can be installed via pip:\n```\npip install iterative-stratification\n```\n\n## Toy Examples\nThe multilabel cross validators that this package provides may be used with the scikit-learn API in the same manner as any other cross validators. For example, these cross validators may be passed to [cross_val_score](http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_score.html) or [cross_val_predict](http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_predict.html). Below are some toy examples of the direct use of the multilabel cross validators.\n\n### MultilabelStratifiedKFold\n```python\nfrom iterstrat.ml_stratifiers import MultilabelStratifiedKFold\nimport numpy as np\n\nX = np.array([[1,2], [3,4], [1,2], [3,4], [1,2], [3,4], [1,2], [3,4]])\ny = np.array([[0,0], [0,0], [0,1], [0,1], [1,1], [1,1], [1,0], [1,0]])\n\nmskf = MultilabelStratifiedKFold(n_splits=2, shuffle=True, random_state=0)\n\nfor train_index, test_index in mskf.split(X, y):\n   print(\"TRAIN:\", train_index, \"TEST:\", test_index)\n   X_train, X_test = X[train_index], X[test_index]\n   y_train, y_test = y[train_index], y[test_index]\n```\nOutput:\n```\nTRAIN: [0 3 4 6] TEST: [1 2 5 7]\nTRAIN: [1 2 5 7] TEST: [0 3 4 6]\n```\n### RepeatedMultilabelStratifiedKFold\n```python\nfrom iterstrat.ml_stratifiers import RepeatedMultilabelStratifiedKFold\nimport numpy as np\n\nX = np.array([[1,2], [3,4], [1,2], [3,4], [1,2], [3,4], [1,2], [3,4]])\ny = np.array([[0,0], [0,0], [0,1], [0,1], [1,1], [1,1], [1,0], [1,0]])\n\nrmskf = RepeatedMultilabelStratifiedKFold(n_splits=2, n_repeats=2, random_state=0)\n\nfor train_index, test_index in rmskf.split(X, y):\n   print(\"TRAIN:\", train_index, \"TEST:\", test_index)\n   X_train, X_test = X[train_index], X[test_index]\n   y_train, y_test = y[train_index], y[test_index]\n```\nOutput:\n```\nTRAIN: [0 3 4 6] TEST: [1 2 5 7]\nTRAIN: [1 2 5 7] TEST: [0 3 4 6]\nTRAIN: [0 1 4 5] TEST: [2 3 6 7]\nTRAIN: [2 3 6 7] TEST: [0 1 4 5]\n```\n### MultilabelStratifiedShuffleSplit\n```python\nfrom iterstrat.ml_stratifiers import MultilabelStratifiedShuffleSplit\nimport numpy as np\n\nX = np.array([[1,2], [3,4], [1,2], [3,4], [1,2], [3,4], [1,2], [3,4]])\ny = np.array([[0,0], [0,0], [0,1], [0,1], [1,1], [1,1], [1,0], [1,0]])\n\nmsss = MultilabelStratifiedShuffleSplit(n_splits=3, test_size=0.5, random_state=0)\n\nfor train_index, test_index in msss.split(X, y):\n   print(\"TRAIN:\", train_index, \"TEST:\", test_index)\n   X_train, X_test = X[train_index], X[test_index]\n   y_train, y_test = y[train_index], y[test_index]\n```\nOutput:\n```\nTRAIN: [1 2 5 7] TEST: [0 3 4 6]\nTRAIN: [2 3 6 7] TEST: [0 1 4 5]\nTRAIN: [1 2 5 6] TEST: [0 3 4 7]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrent-b%2Fiterative-stratification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrent-b%2Fiterative-stratification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrent-b%2Fiterative-stratification/lists"}