Skip to main content

Multi-instance machine learning in Python

Project description

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:

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

mikit_learn-1.0.2.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

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

mikit_learn-1.0.2-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file mikit_learn-1.0.2.tar.gz.

File metadata

  • Download URL: mikit_learn-1.0.2.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for mikit_learn-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f6945987376f48c11d21ef53345d011b8edb501be9875aa3c0900a4da7d25325
MD5 d2a41cff6043e5164503516c6b0e5bb4
BLAKE2b-256 3bafe262908a601904bf14603a54fea07bf36e327073f7d3a8831ec403f25290

See more details on using hashes here.

File details

Details for the file mikit_learn-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mikit_learn-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for mikit_learn-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 638771371ea8553db138c7cbe4cbb09df6a17cb28fa950bd083742ac5e047432
MD5 5df5fc776ee082ec01bc93afd785eb89
BLAKE2b-256 4b64d7efeeb2004148b83b2a7109d799b0c9da8c0bfe9f3c9aa9b283d3ef5fb7

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