llp-learn
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)
# LLP model (DLLP)
llp_model = DLLP(model_type="simple-mlp", lr=0.0001, n_epochs=1000, hidden_layer_sizes=(100, 100), n_jobs=0)
# 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.
Metadata
Release files for llp-learn 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llp_learn-1.6.0.tar.gz | 26.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llp_learn-1.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 65.2 kB
Release files / llp_learn-1.6.0.tar.gz
| Download URL | llp_learn-1.6.0.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec825839f01275ce4e411c34c3235b79ddab88c3eec59a2c31f1104302cd1c6a
|
|
BLAKE2b-256 checksum How to use checksums |
af360f48be087b3c1a459e9b7f2e8ec5a6839640357e36d30b30880a86f94a3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.24.1
|
Release files / llp_learn-1.6.0-py3-none-any.whl
| Download URL | llp_learn-1.6.0-py3-none-any.whl |
|---|---|
| Size | 39.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22a520cf4180822e7c880508b16b30d736253e365365009942f69516269f6d51
|
|
BLAKE2b-256 checksum How to use checksums |
25caa1688498502181fd05c344d60420213f1b2f7487d04096dd7d0c799c0c39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.24.1
|