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.1.tar.gz (20.2 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.1-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mikit_learn-1.0.1.tar.gz
Algorithm Hash digest
SHA256 93a2f70ca15ebc2f82b83f312a2a6f76f4bbed669e137ba4ca39edd9918985da
MD5 788f5e504fec897f6c8b76560aff8272
BLAKE2b-256 0cd50eb585628dc3a4a1290ff0ca965e4645600560dc4f5841f8170ca37fa931

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mikit_learn-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 461993e9a45f1792b590c13f1207976c04eac3c85da0d4a51036ed52550ab6a2
MD5 1ee850c11092443b60d4ddf31f67ca94
BLAKE2b-256 176b1f92c446346210aca16ca6e1f8c4a3b25b7da7bbc64ab2df53c7b7c68ce6

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