{"id":23904,"library":"iterative-stratification","title":"Iterative Stratification","description":"Provides scikit-learn compatible cross-validators with stratification for multilabel data. Current version 0.1.9, release cadence is sporadic.","status":"active","version":"0.1.9","language":"python","source_language":"en","source_url":"https://github.com/trent-b/iterative-stratification","tags":["multilabel","stratification","cross-validation","scikit-learn"],"install":[{"cmd":"pip install iterative-stratification","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Base classes and compatibility","package":"scikit-learn","optional":false},{"reason":"Array operations","package":"numpy","optional":false},{"reason":"Sparse matrix support","package":"scipy","optional":false}],"imports":[{"note":"Package name is iterstrat, not iterative-stratification","wrong":"from iterative_stratification import ...","symbol":"MultilabelStratifiedKFold","correct":"from iterstrat.ml_stratifiers import MultilabelStratifiedKFold"},{"note":"","wrong":null,"symbol":"MultilabelStratifiedShuffleSplit","correct":"from iterstrat.ml_stratifiers import MultilabelStratifiedShuffleSplit"}],"quickstart":{"code":"import numpy as np\nfrom iterstrat.ml_stratifiers import MultilabelStratifiedKFold\n\nX = np.random.rand(20, 5)\ny = np.random.randint(0, 2, (20, 3))  # multilabel binary indicator matrix\n\nkf = MultilabelStratifiedKFold(n_splits=5, shuffle=True, random_state=42)\nfor train_index, test_index in kf.split(X, y):\n    print(\"Train:\", train_index, \"Test:\", test_index)","lang":"python","description":"Simple usage of MultilabelStratifiedKFold for multilabel classification."},"warnings":[{"fix":"Upgrade to iterstrat 0.1.7 or higher.","message":"scikit-learn 1.0 introduced extra parameter warnings; version 0.1.7+ handles these but if using older version, expect deprecation warnings.","severity":"deprecated","affected_versions":"<0.1.7"},{"fix":"Use 'from iterstrat.ml_stratifiers import ...'","message":"The package is imported as 'iterstrat', not 'iterative-stratification' or 'iterative_stratification'. Many users mistakenly use the PyPI name.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure y is shape (n_samples, n_labels) with values 0 or 1.","message":"The cross-validator expects y to be a binary indicator matrix (2d array of 0/1), not label indices. Use MultiLabelBinarizer from sklearn.preprocessing to convert.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change imports to 'from iterstrat.ml_stratifiers import MultilabelStratifiedKFold'","cause":"Incorrect import name; the actual module is 'iterstrat'.","error":"ModuleNotFoundError: No module named 'iterative_stratification'"},{"fix":"Convert labels to binary indicator matrix using sklearn.preprocessing.MultiLabelBinarizer.","cause":"y provided as a 1d array or single-label; iterative stratification requires multilabel binary matrix.","error":"ValueError: The number of classes has to be greater than one"},{"fix":"Upgrade to iterstrat >=0.1.7.","cause":"Using older version (<0.1.7) with scikit-learn 1.0+.","error":"DeprecationWarning: Passing 'n_splits' without 'n_splits' as a keyword argument is deprecated"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}