Skip to main content

Learning from Label Proportions (LLP) methods in Python

Project description

llp-learn

PyPI - Version PyPI - Python Version

LLP-learn is a library that provides implementation of methods for Learning from Label Proportions.


Table of Contents

Installation

pip install llp-learn

Usage

import numpy as np
from sklearn.datasets import make_classification
from sklearn.metrics import classification_report
from llp_learn.dllp import DLLP
from llp_learn.model_selection import gridSearchCV

random = np.random.RandomState(42)

# Creating a syntetic dataset using sklearn
X, y = make_classification(n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1, n_samples=1000, random_state=42)

# Generating 5 bags randomly
bags = random.randint(0, 5, size=X.shape[0])

# Creating the proportions
proportions = np.zeros(5)
for i in range(5):
    bag_i = np.where(bags == i)[0]
    proportions[i] = y[bag_i].sum() / len(bag_i)

# Labels must be -1 and 1
y[y == 0] = -1

# LLP model (DLLP)
llp_model = DLLP(lr=0.0001, n_epochs=1000, hidden_layer_sizes=(100, 100))

# Grid Search the lr parameter
gs = gridSearchCV(llp_model, param_grid={"lr": [0.1, 0.01, 0.001, 0.0001]}, cv=5, validation_size=0.5, n_jobs=-1, random_state=42)

# Train/test split
train_idx = random.choice(np.arange(X.shape[0]), size=int(X.shape[0] * 0.8), replace=False)
test_idx = np.setdiff1d(np.arange(X.shape[0]), train_idx)

# Fitting the model
gs.fit(X[train_idx], bags[train_idx], proportions)

# Predicting the labels of the test set
y_pred_test = gs.predict(X[test_idx])

# Reporting the performance of the model in the test set
print(classification_report(y[test_idx], y_pred_test))

License

llp-learn is distributed under the terms of the MIT license.

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

llp_learn-1.1.1.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

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

llp_learn-1.1.1-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file llp_learn-1.1.1.tar.gz.

File metadata

  • Download URL: llp_learn-1.1.1.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for llp_learn-1.1.1.tar.gz
Algorithm Hash digest
SHA256 7a0e9b4def65ba1ba31827aa6dcf0abc0ac9de6a8279272a04fc36d029bb4418
MD5 8423830a10c3966f498ee60f5a66ff0b
BLAKE2b-256 a760b8bb6491f2851a301c2078409c62ec96d05d89d41f241a5941c2ef7b4b33

See more details on using hashes here.

File details

Details for the file llp_learn-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: llp_learn-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for llp_learn-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f2b05e682cf0d3aaa6d7a340a501e5a56e81999371c3ccaab54ecb5d5899ac3
MD5 7fee788361d99fc30515560713fbe333
BLAKE2b-256 0e883652ad4e365563359e21f7cc3bd68e5af24a8c33c61ec55e6333f1a4edc2

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