Skip to main content

milwrap - multiple instane meta-learner that can use any supervised-learning algorithms.

Project description

milwrap

Python Tests GitHub issues Open In Colab

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)
  • support multi-class setting
  • support scikit-learn algorithms (such as RandomForestClassifier, SVC, LogisticRegression)

Installation

pip install milwrap

Usage

For more information, see Use scikit-learn models in multiple instance learning based on the count-based assumption.

# 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

milwrap-0.2.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

milwrap-0.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file milwrap-0.2.0.tar.gz.

File metadata

  • Download URL: milwrap-0.2.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for milwrap-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6a5eade323f4f705ad6d61d1f9c688581a5d4bb54b82af1f9ce745a69b823757
MD5 6b19213212faa353591fb1b0e0477c19
BLAKE2b-256 4cfb3dd6a131b3efd470e46775e9861dff2fada5db3430ebb091bafcac00dce0

See more details on using hashes here.

File details

Details for the file milwrap-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: milwrap-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for milwrap-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e31bb8edeaff7ad1a3f8f781a17f378f9643ba96738e01ea61057c6c93ee3b24
MD5 bcda1a556ba36160f07e95152494c061
BLAKE2b-256 648685a943b1b599b72aaf4cefa28a861d9c559e61584e6c52b7f1a53fecbcd8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page