Skip to main content

milearn: Multi-instance machine learning in Python

milearn is designed to mimic the scikit-learn interface to simplify its usage and integration with other tools.

Key Features

  • Traditional and neural network-based MIL algorithms (regression and classification)

  • Integrated stepwise model hyperparameter optimization (recommended for small datasets)

Installation

pip install mikit-learn

Quick Start

from milearn.data.mnist import load_mnist, create_bags_reg
from milearn.preprocessing import BagMinMaxScaler
from sklearn.model_selection import train_test_split
from milearn.network.module.hopt import DEFAULT_PARAM_GRID
from milearn.network.regressor import DynamicPoolingNetworkRegressor

# 1. Create MNIST regression dataset
data, targets = load_mnist()
bags, labels, key = create_bags_reg(data, targets, bag_size=10, num_bags=10000,
                                    bag_agg="mean", random_state=42)

# 2. Train/test split and scale features
x_train, x_test, y_train, y_test, key_train, key_test = train_test_split(bags, labels, key,
                                                                         random_state=42)
scaler = BagMinMaxScaler()
scaler.fit(x_train)
x_train_scaled = scaler.transform(x_train)
x_test_scaled = scaler.transform(x_test)

# 3. Train model
model = DynamicPoolingNetworkRegressor()
model.hopt(x_train_scaled, y_train,  # recommended for small datasets only
           param_grid=DEFAULT_PARAM_GRID, verbose=True)
model.fit(x_train_scaled, y_train)

# 4. Get predictions
y_pred = model.predict(x_test_scaled)  # predicted labels
w_pred = model.get_instance_weights(x_test_scaled)  # predicted instance weights

Tutorials

Several examples of the milearn application to the classification/regression problem and key instance detection for the MNIST dataset can be found in tutorial collection .

Paper

Warning: currently, notebooks for reproducing paper results are migrating between milearn and QSARmil, so some may be unavailable for some time.

Application cases demonstrated in the paper can be found in:

Citation

For milearn citation use:

@article{zankov2025milearn,
  title={milearn: A Python Package for Multi-Instance Machine Learning},
  author={Zankov, Dmitry and Polishchuk, Pavlo and Sobieraj, Michal and Barbatti, Mario},
  journal={arXiv preprint arXiv:2512.01287},
  year={2025}
}

Metadata

Release files for mikit-learn 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mikit-learn 1.0.6
File Size Uploaded
mikit_learn-1.0.6.tar.gz 19.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mikit-learn 1.0.6
File Interpreter ABI Platform
mikit_learn-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 46.7 kB

Release files / mikit_learn-1.0.6.tar.gz

Download URL mikit_learn-1.0.6.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c903a226ecb9a99c5456a1e4ad7c5cd7ac47ebb7fb45afafbd3dfe66e77ffc69
BLAKE2b-256 checksum
How to use checksums
e7a4953d8f3e9587a632cc28bc0301b026942f29079cc5cb5b41ef3ae7c7c6e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log

Release files / mikit_learn-1.0.6-py3-none-any.whl

Download URL mikit_learn-1.0.6-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e44e9d8e426558b03acb544b3963975a00492ae90930d029b4e1bf6cc8cf55b
BLAKE2b-256 checksum
How to use checksums
f2f0fd1162b427bb463ffc64388595bdee9b46d8829799e2ea55fd59ba594c7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page