milwrap


Namemilwrap JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/inoueakimitsu/milwrap
Summarymilwrap - multiple instane meta-learner that can use any supervised-learning algorithms.
upload_time2025-01-24 06:34:53
maintainerNone
docs_urlNone
authorAkimitsu Inoue
requires_python>=3.10
licenseMIT
keywords machine learning
VCS
bugtrack_url
requirements joblib numpy pandas python-dateutil pytz scikit-learn scipy six threadpoolctl tzdata
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # milwrap

[![Python Tests](https://github.com/inoueakimitsu/milwrap/actions/workflows/python-tests.yml/badge.svg)](https://github.com/inoueakimitsu/milwrap/actions/workflows/python-tests.yml)
<a href="https://github.com/inoueakimitsu/milwrap/issues"><img alt="GitHub issues" src="https://img.shields.io/github/issues/inoueakimitsu/milwrap"></a>
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/inoueakimitsu/milwrap/blob/master/introduction.ipynb)

Python package for multiple instance learning (MIL).
This wraps single instance learning algorithms so that they can be fitted to data for MIL.

## Features

- support count-based multiple instance assumptions (see [wikipedia](https://en.wikipedia.org/wiki/Multiple_instance_learning#:~:text=Presence-%2C%20threshold-%2C%20and%20count-based%20assumptions%5Bedit%5D))
- support multi-class setting
- support scikit-learn algorithms (such as `RandomForestClassifier`, `SVC`, `LogisticRegression`)

## Installation

```bash
pip install milwrap
```

## Usage

For more information, see [Use scikit-learn models in multiple instance learning based on the count-based assumption](https://github.com/inoueakimitsu/milwrap/blob/main/intro-en.md).

```python
# Prepare single-instance supervised-learning algorithm
# Note: only supports models with predict_proba() method.
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()

# Wrap it with MilCountBasedMultiClassLearner
from milwrap import MilCountBasedMultiClassLearner
mil_learner = MilCountBasedMultiClassLearner(clf)

# Prepare follwing dataset
#
# - bags ... list of np.ndarray
#            (num_instance_in_the_bag * num_features)
# - lower_threshold ... np.ndarray (num_bags * num_classes)
# - upper_threshold ... np.ndarray (num_bags * num_classes)
#
# bags[i_bag] contains not less than lower_thrshold[i_bag, i_class]
# i_class instances.

# run multiple instance learning
clf_mil, y_mil = learner.fit(
    bags,
    lower_threshold,
    upper_threshold,
    n_classes,
    max_iter=10)

# after multiple instance learning,
# you can predict instance class
clf_mil.predict([instance_feature])
```

See `tests/test_countbased.py` for an example of a fully working test data generation process.

## License

milwrap is available under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/inoueakimitsu/milwrap",
    "name": "milwrap",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "machine learning",
    "author": "Akimitsu Inoue",
    "author_email": "akimitsu.inoue@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4c/fb/3dd6a131b3efd470e46775e9861dff2fada5db3430ebb091bafcac00dce0/milwrap-0.2.0.tar.gz",
    "platform": null,
    "description": "# milwrap\n\n[![Python Tests](https://github.com/inoueakimitsu/milwrap/actions/workflows/python-tests.yml/badge.svg)](https://github.com/inoueakimitsu/milwrap/actions/workflows/python-tests.yml)\n<a href=\"https://github.com/inoueakimitsu/milwrap/issues\"><img alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/inoueakimitsu/milwrap\"></a>\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/inoueakimitsu/milwrap/blob/master/introduction.ipynb)\n\nPython package for multiple instance learning (MIL).\nThis wraps single instance learning algorithms so that they can be fitted to data for MIL.\n\n## Features\n\n- support count-based multiple instance assumptions (see [wikipedia](https://en.wikipedia.org/wiki/Multiple_instance_learning#:~:text=Presence-%2C%20threshold-%2C%20and%20count-based%20assumptions%5Bedit%5D))\n- support multi-class setting\n- support scikit-learn algorithms (such as `RandomForestClassifier`, `SVC`, `LogisticRegression`)\n\n## Installation\n\n```bash\npip install milwrap\n```\n\n## Usage\n\nFor more information, see [Use scikit-learn models in multiple instance learning based on the count-based assumption](https://github.com/inoueakimitsu/milwrap/blob/main/intro-en.md).\n\n```python\n# Prepare single-instance supervised-learning algorithm\n# Note: only supports models with predict_proba() method.\nfrom sklearn.linear_model import LogisticRegression\nclf = LogisticRegression()\n\n# Wrap it with MilCountBasedMultiClassLearner\nfrom milwrap import MilCountBasedMultiClassLearner\nmil_learner = MilCountBasedMultiClassLearner(clf)\n\n# Prepare follwing dataset\n#\n# - bags ... list of np.ndarray\n#            (num_instance_in_the_bag * num_features)\n# - lower_threshold ... np.ndarray (num_bags * num_classes)\n# - upper_threshold ... np.ndarray (num_bags * num_classes)\n#\n# bags[i_bag] contains not less than lower_thrshold[i_bag, i_class]\n# i_class instances.\n\n# run multiple instance learning\nclf_mil, y_mil = learner.fit(\n    bags,\n    lower_threshold,\n    upper_threshold,\n    n_classes,\n    max_iter=10)\n\n# after multiple instance learning,\n# you can predict instance class\nclf_mil.predict([instance_feature])\n```\n\nSee `tests/test_countbased.py` for an example of a fully working test data generation process.\n\n## License\n\nmilwrap is available under the MIT License.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "milwrap - multiple instane meta-learner that can use any supervised-learning algorithms.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/inoueakimitsu/milwrap",
        "Repository": "https://github.com/inoueakimitsu/milwrap"
    },
    "split_keywords": [
        "machine",
        "learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "648685a943b1b599b72aaf4cefa28a861d9c559e61584e6c52b7f1a53fecbcd8",
                "md5": "bcda1a556ba36160f07e95152494c061",
                "sha256": "e31bb8edeaff7ad1a3f8f781a17f378f9643ba96738e01ea61057c6c93ee3b24"
            },
            "downloads": -1,
            "filename": "milwrap-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bcda1a556ba36160f07e95152494c061",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6063,
            "upload_time": "2025-01-24T06:34:51",
            "upload_time_iso_8601": "2025-01-24T06:34:51.984244Z",
            "url": "https://files.pythonhosted.org/packages/64/86/85a943b1b599b72aaf4cefa28a861d9c559e61584e6c52b7f1a53fecbcd8/milwrap-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cfb3dd6a131b3efd470e46775e9861dff2fada5db3430ebb091bafcac00dce0",
                "md5": "6b19213212faa353591fb1b0e0477c19",
                "sha256": "6a5eade323f4f705ad6d61d1f9c688581a5d4bb54b82af1f9ce745a69b823757"
            },
            "downloads": -1,
            "filename": "milwrap-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6b19213212faa353591fb1b0e0477c19",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5085,
            "upload_time": "2025-01-24T06:34:53",
            "upload_time_iso_8601": "2025-01-24T06:34:53.200328Z",
            "url": "https://files.pythonhosted.org/packages/4c/fb/3dd6a131b3efd470e46775e9861dff2fada5db3430ebb091bafcac00dce0/milwrap-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-24 06:34:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "inoueakimitsu",
    "github_project": "milwrap",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "joblib",
            "specs": [
                [
                    "==",
                    "1.4.2"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "2.2.2"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    "==",
                    "2.2.3"
                ]
            ]
        },
        {
            "name": "python-dateutil",
            "specs": [
                [
                    "==",
                    "2.9.0.post0"
                ]
            ]
        },
        {
            "name": "pytz",
            "specs": [
                [
                    "==",
                    "2024.2"
                ]
            ]
        },
        {
            "name": "scikit-learn",
            "specs": [
                [
                    "==",
                    "1.6.1"
                ]
            ]
        },
        {
            "name": "scipy",
            "specs": [
                [
                    "==",
                    "1.15.1"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    "==",
                    "1.17.0"
                ]
            ]
        },
        {
            "name": "threadpoolctl",
            "specs": [
                [
                    "==",
                    "3.5.0"
                ]
            ]
        },
        {
            "name": "tzdata",
            "specs": [
                [
                    "==",
                    "2025.1"
                ]
            ]
        }
    ],
    "lcname": "milwrap"
}
        
Elapsed time: 1.92424s