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

Application cases demonstrated in the paper can be found in:

Metadata

Release files for mikit-learn 1.0.4

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.4
File Size Uploaded
mikit_learn-1.0.4.tar.gz 20.7 kB Details

Built distribution (wheel)

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

Total release size: 47.8 kB

Release files / mikit_learn-1.0.4.tar.gz

Download URL mikit_learn-1.0.4.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9cf22210d1705f13209b61f9f151c834ae28f98442f44043328e1f296a7d48e9
BLAKE2b-256 checksum
How to use checksums
18457bb4eefffb50668d7342083706bb95ada68ab1fdcc554e2812fecb741d33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

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

Download URL mikit_learn-1.0.4-py3-none-any.whl
Size 27.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4a6faa14989b9650285eaf101032ddb55bed89f37942d7406ef1c47957c0898
BLAKE2b-256 checksum
How to use checksums
7eccad39c72db9f64fc212cdcb8c5c34878827d97671e9f9434661772b3f8036
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

Release history Release notifications | RSS feed

1.0.6

2 release files

1.0.5

2 release files

This release

1.0.4 This release

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