This repo contains the implementation of Multi-Instance Logistic Regression in PyTorch.
The library offers several alternatives for definining the relationship between the instance probability,
Name | Relation | Option name |
---|---|---|
Max | max | |
Logsumexp | logsumexp | |
Generalized mean | generalized_mean | |
Product | product | |
Likelihood ratio | likelihood_ratio |
Here's how to create an instance of the MILR
class and train it:
mkdir data
get_example_data.sh
from milr import MILR
from mil import make_dataset_from_dataframe
model = MILR()
# Prepare your data
raw_data = loadarff('./data/musk2/musk.arff')
data = pd.DataFrame(raw_data[0])
data.rename(columns={'class': 'target'}, inplace=True)
data.target = data.target.astype(int)
feature_names = [f'f{i}' for i in range(1, 167)]
X, y, bags = make_dataset_from_dataframe(data, feature_names, 'target', 'molecule_name')
# Train the model
model.fit(X, y, bags, epochs=100, lr=1e-2, bag_fn='max')