Skip to main content

A tool to create well-balanced data splits for multi-task learning

Project description

Globally balanced multi-task splits

A tool to create well-balanced multi-task splits without data leakage between different tasks for QSAR modelling.

This package is based on the work of Giovanni Tricarico presented in Construction of balanced, chemically dissimilar training, validation and test sets for machine learning on molecular datasets.

Three splits are available: random-, dissimilarity- (clustering based on Tanimoto similarity of fingerprints with MaxMin or LeaderPicker) and scaffold-based (clustering based on Murcko scaffolds).

Installation

pip install gbmt-splits

Getting started

CLI

The split can be easily created from the command line with

gbmtsplits -i <dataset.csv> -c <random/dissimilarity_maxmin/dissimilarity_leader/scaffold> 

with <datasets.csv> an pivoted dataset where each row corresponds to a unique molecules and each task has it's own column. For more options use -h/--help.

API

The splits can be also created (more options for linear programming to merge initial clusters) and visualised with an API.

import pandas as pd
from gbmtsplits.split import GloballyBalancedSplit
from gbmtsplits.clustering import RandomClustering, MaxMinClustering, LeaderPickerClustering, MurckoScaffoldClustering

# Load dataset or create pivoted dataset (each row corresponds to a unique molecules and each task has it's own column)
dataset = pd.read_csv('dataset.csv')

# Set up splitter with a initial clustering method
clustering_method = MaxMinClustering() # For dissimilarity based clustering using MaxMin algorithm to pick cluster centroids
splitter = GloballyBalancedSplit(clustering_method=clustering_method)

# or use dictionnary with precalculates clusters with keys cluster indices and values list of indices of molecules part of the cluster
clusters = {0 : [1,4,7,...], 1 : [2,3,8,...], ...}
splitter = GloballyBalancedSplit(clusters=clusters)

# Split the data
data = splitter(data=data)

The chemical (dis)similarity of the subsets and the balance of subsets per task can visualized either for a single dataset/split:

from gbmtsplits.plot import PlottingSingleDataset
plotter = PlottingSingleDataset(data_rgbs)
plotter.plot_all()

or to compare multiple datasets/splits:

from gbmtsplits.plot import PlottingCompareDatasets

data_rgbs['Dataset'] = 'RGBS'
data_dgbs['Dataset'] = 'DGBS'
data_both = pd.concat([data_rgbs, data_dgbs], ignore_index=True])

plotter = PlottingCompareDatasets(data_both, compare_col='Dataset')
plotter.plot_all()

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

gbmtsplits-0.0.7.tar.gz (73.7 kB view details)

Uploaded Source

Built Distribution

gbmtsplits-0.0.7-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file gbmtsplits-0.0.7.tar.gz.

File metadata

  • Download URL: gbmtsplits-0.0.7.tar.gz
  • Upload date:
  • Size: 73.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for gbmtsplits-0.0.7.tar.gz
Algorithm Hash digest
SHA256 39bc6e930fd82400d7af64c7d91522eef0da2db8d97d4e68c4d422e0bbcdb870
MD5 89438ba5b4e520337b2296710a436d9a
BLAKE2b-256 89de11061c282a21bdf61fa58f0fb26226298aed7e1ef584c190c8b2d84f0718

See more details on using hashes here.

File details

Details for the file gbmtsplits-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: gbmtsplits-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 45.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for gbmtsplits-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0e3a268a218946c08d79142bd39cda6fe63fafdfafd4b7e24139ba20db739dc6
MD5 c674d627135156b5bc4a68db6e73c8db
BLAKE2b-256 e0afb6535f49330a83e876af79ec3aa03d48bd314ed29507350841cc72a11d6b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page