Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inoueakimitsu/milwrap
Wrapping single instance learning algorithms for fitting them to data for multiple instance learning
https://github.com/inoueakimitsu/milwrap
large-data machine-learning multi-class-classification multiple-instance-learning python sklearn
Last synced: 11 days ago
JSON representation
Wrapping single instance learning algorithms for fitting them to data for multiple instance learning
- Host: GitHub
- URL: https://github.com/inoueakimitsu/milwrap
- Owner: inoueakimitsu
- License: mit
- Created: 2021-09-29T11:06:11.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-06T22:41:39.000Z (almost 2 years ago)
- Last Synced: 2024-12-09T14:11:09.050Z (19 days ago)
- Topics: large-data, machine-learning, multi-class-classification, multiple-instance-learning, python, sklearn
- Language: Jupyter Notebook
- Homepage:
- Size: 580 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# milwrap
[![Build Status](https://app.travis-ci.com/inoueakimitsu/milwrap.svg?branch=main)](https://app.travis-ci.com/inoueakimitsu/milwrap)
[![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.