clustermil - clustering based multiple instance learning
Project description
clustermil
clustering based multiple instance learning
clustermil
Python package for multiple instance learning (MIL) for large n_instance dataset.
Features
- support count-based multiple instance assumptions (see wikipedia)
- support multi-class setting
- support scikit-learn Clustering algorithms (such as
MiniBatchKMeans
) - fast even if n_instance is large
Installation
pip install clustermil
Usage
# 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.
# Prepare single-instance clustering algorithms
from sklearn.cluster import MiniBatchKMeans
n_clusters = 100
clustering = MiniBatchKMeans(n_clusters=n_clusters)
clusters = clustering.fit_predict(np.vstack(bags)) # flatten bags into instances
# Prepare one-hot encoder
from sklearn.preprocessing import OneHotEncoder
onehot_encoder = OneHotEncoder()
onehot_encoder.fit(clusters)
# generate ClusterMilClassifier with helper function
from clustermil import generate_mil_classifier
milclassifier = generate_mil_classifier(
clustering,
onehot_encoder,
bags,
lower_threshold,
upper_threshold,
n_clusters,
n_epoch = 100,
lr = 0.1,
l1_penalty_coef = 1000,
n_init = 10)
# after multiple instance learning,
# you can predict instance class
milclassifier.predict([instance_feature])
See tests/test_classification.py
for an example of a fully working test data generation process.
License
clustermil is available under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clustermil-0.1.0.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for clustermil-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5910b7ba3b77ace5451f772028c3d2d6fa3d59a4c9fcdd83d06bdce98beb9b3b |
|
MD5 | 6231739365f4705bd328dd0bf00db940 |
|
BLAKE2b-256 | 0108192ecf48ccdabfd6a1cd992c7e95609a02b5aa6ca0e3781da0b7fec4f435 |