{"id":50556017,"url":"https://github.com/lucidfrontier45/milgboost","last_synced_at":"2026-06-05T08:00:33.253Z","repository":{"id":361209104,"uuid":"1253431033","full_name":"lucidfrontier45/milgboost","owner":"lucidfrontier45","description":"Multiple Instance Learning for Gradient Boosting Models","archived":false,"fork":false,"pushed_at":"2026-05-30T10:55:46.000Z","size":669,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-04T07:25:07.112Z","etag":null,"topics":["ai","gradient-boosting","lightgbm","machine-learning","multiple-instance-learning","python","xgboost"],"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/lucidfrontier45.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":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-05-29T13:03:38.000Z","updated_at":"2026-05-30T10:55:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/lucidfrontier45/milgboost","commit_stats":null,"previous_names":["lucidfrontier45/milgboost"],"tags_count":1,"template":false,"template_full_name":"lucidfrontier45/python-uv-template","purl":"pkg:github/lucidfrontier45/milgboost","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Fmilgboost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Fmilgboost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Fmilgboost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Fmilgboost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidfrontier45","download_url":"https://codeload.github.com/lucidfrontier45/milgboost/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Fmilgboost/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33935514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-05T02:00:06.157Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ai","gradient-boosting","lightgbm","machine-learning","multiple-instance-learning","python","xgboost"],"created_at":"2026-06-04T07:02:23.659Z","updated_at":"2026-06-05T08:00:33.153Z","avatar_url":"https://github.com/lucidfrontier45.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"logo.png\" alt=\"milgboost logo\" width=\"500\"\u003e\n\nMIL is a weakly supervised learning paradigm where labels are available for _bags_ (groups of instances) rather than individual instances. `milgboost` brings MIL to gradient boosting by wrapping LightGBM and XGBoost with custom differentiable objectives — currently the **LogSumExp Binary Cross-Entropy (LSE-BCE)** loss, a smooth approximation of the max-instance MIL loss.\n\n## Installation\n\n```shell\nuv add milgboost\n```\n\n### Extra options\n\nInstall with a specific boosting backend:\n\n```shell\nuv add milgboost[xgboost-cpu]\nuv add milgboost[xgboost] # GPU enabled\nuv add milgboost[lightgbm]\nuv add milgboost[xgboost-cpu,lightgbm]\n```\n\n## Module overview\n\n| Module                     | Description                                                     |\n| -------------------------- | --------------------------------------------------------------- |\n| `milgboost.types`          | `Bag` / `LabeledBag` dataclasses + array↔bag conversion helpers |\n| `milgboost.datasets`       | `make_mil_data()` — synthetic MIL data generator                |\n| `milgboost.model.base`     | `BaseMILModel` abstract class (fit / predict / predict_proba)   |\n| `milgboost.model.xgboost`  | `XGBoostMILModel` — XGBoost-backed MIL classifier               |\n| `milgboost.model.lightgbm` | `LightGBMMILModel` — LightGBM-backed MIL classifier             |\n| `milgboost.objective.base` | `BaseMILObjective` abstract interface for custom MIL objectives |\n| `milgboost.objective.lse`  | `LSEBCE` — LogSumExp binary cross-entropy objective             |\n\n## Output ordering\n\nAll prediction methods (`predict`, `predict_proba`, `predict_bags`, `predict_proba_bags`) return results **sorted by bag_id in ascending order**. For example, if your bag IDs are `[3, 1, 2]`, the output will be ordered as bags `[1, 2, 3]`.\n\n**Recommendation**: Sort both `x` and `z` by `z` values before prediction to ensure output aligns with your expected ordering:\n\n```python\n# Sort x and z by z values before prediction\nsort_idx = np.argsort(z)\nx_sorted, z_sorted = x[sort_idx], z[sort_idx]\n\n# Predictions will follow the sorted order\nprobs = model.predict_proba(x_sorted, z_sorted)\n# probs[i] corresponds to bag i (after sorting)\n```\n\nUsing sequential bag IDs (0, 1, 2, ...) is the simplest approach to avoid confusion.\n\n## Sample code\n\n```python\nimport numpy as np\nfrom milgboost.datasets import make_mil_data\nfrom milgboost.objective import LSEBCE\nfrom milgboost.model import LightGBMMILModel\n\n# Generate synthetic MIL data: 200 bags, 10 features\nx, y, z = make_mil_data(\n    n_bags=200,\n    n_features=10,\n    n_informative=5,\n    key_instance_ratio=0.3,\n    random_state=42,\n)\n\n# Split into train/test bags\nn_train = 150\ntrain_idx = z \u003c n_train\ntest_idx = z \u003e= n_train\n\nx_train, y_train, z_train = x[train_idx], y[train_idx], z[train_idx]\nx_test, y_test, z_test = x[test_idx], y[test_idx], z[test_idx]\n\n# Train LSE-BCE LightGBM MIL model\nmodel = LightGBMMILModel(\n    objective=LSEBCE(r=1.0),\n    lgb_params={\"verbose\": -1, \"num_leaves\": 15},\n    num_boost_round=100,\n)\nmodel.fit(x_train, y_train, z_train)\n\n# Predict\nprobs = model.predict_proba(x_test, z_test)\npreds = model.predict(x_test, z_test)\nprint(f\"Accuracy: {(preds == y_test[: len(preds)]).mean():.3f}\")\n```\n\n## Development\n\n```shell\ngit clone \u003crepo\u003e\ncd milgboost\n\n# Create virtualenv and install all extras + dev deps\nuv sync --all-extras --group dev\n\n# Type check\nuv run poe check\n\n# Lint \u0026 format\nuv run poe lint\nuv run poe format\n\n# Run tests\nuv run poe test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidfrontier45%2Fmilgboost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidfrontier45%2Fmilgboost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidfrontier45%2Fmilgboost/lists"}