Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Usage Examples to Splitters #3241

Merged
merged 5 commits into from
Feb 22, 2023
Merged

Conversation

GreatRSingh
Copy link
Contributor

@GreatRSingh GreatRSingh commented Feb 14, 2023

Pull Request Template

Description

Fix #3230

This PR aims to add example documentation for Splitters.

  • RandomSplitter - Already Done
  • RandomGroupSplitter
  • RandomStratifiedSplitter
  • SingletaskStratifiedSplitter - Already Done
  • IndexSplitter
  • SpecifiedSplitter
  • MolecularWeightSplitter
  • MaxMinSplitter
  • ButinaSplitter
  • FingerprintSplitter
  • ScaffoldSplitter - Already Done

Type of change

Please check the option that is related to your PR.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • In this case, we recommend to discuss your modification on GitHub issues before creating the PR
  • Documentations (modification for documents)

Checklist

  • My code follows the style guidelines of this project
    • Run yapf -i <modified file> and check no errors (yapf version must be 0.32.0)
    • Run mypy -p deepchem and check no errors
    • Run flake8 <modified file> --count and check no errors
    • Run python -m doctest <modified file> and check no errors
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

@GreatRSingh
Copy link
Contributor Author

@gusty1g sir, check the example for MolecularWeightSplitter.

>>> y = np.random.rand(n_samples, n_tasks)
>>> splitter = dc.splits.IndexSplitter()
>>> dataset = dc.data.NumpyDataset(X, y)
>>> train_dataset, valid_dataset , test_dataset = splitter.split(dataset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A splitter.split method will return indices for split and not datasets. Instead, if we use train_dataset, test_dataset = splitter.train_test_split(dataset), it will be more correct.

Also, the example should demonstrate how the splitter works. I would rewrite it something like this:

n_samples = 5
n_features = 2
X = np.random.rand(n_samples, n_features)
y = np.random.rand(n_samples)
splitter = dc.splits.IndexSplitter()
dataset = dc.data.NumpyDataset(X, y)

>>> train_dataset, test_dataset = splitter.train_test_split(dataset)

>>> print(train_dataset.ids)
[0, 1, 2]
>>> print (test_dataset.ids)
[3, 4]

The above example demonstrates how the splitter splits by index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mistook split function for something else.
I fixed that in the latest commit.

>>> y = np.random.rand(n_samples, n_tasks)
>>> splitter = dc.splits.SpecifiedSplitter(valid_indices=[1,3,5], test_indices=[0,2,7,9])
>>> dataset = dc.data.NumpyDataset(X, y)
>>> train_dataset, valid_dataset , test_dataset = splitter.split(dataset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment for IndexSplitter.

@GreatRSingh
Copy link
Contributor Author

GreatRSingh commented Feb 16, 2023

@gusty1g can you suggest example for RandomGroupSplitter. I am having difficulty in making example for it.
In the group parameter.

@rbharath rbharath mentioned this pull request Feb 17, 2023
15 tasks
@arunppsg
Copy link
Contributor

@gusty1g can you suggest example for RandomGroupSplitter. I am having difficulty in making example for it. In the group parameter.

import deepchem as dc
import numpy as np

groups = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
splitter = dc.splits.RandomGroupSplitter(groups=groups)

dataset = dc.data.NumpyDataset(X=np.arange(12))   # 12 elements
train, test = splitter.train_test_split(dataset, frac_train=0.75, seed=0)

print (train.ids)  # array([6, 7, 8, 9, 10, 11, 3, 4, 5], dtype=object) 

In above example, note that the values 6, 7, 8 belong to a group (2), 9, 10, 11 belong to another group (3) and 3 4 5 belong to group 1. The splitter preserves the group (i.e a group goes either into train or test) while splitting the dataset.

@arunppsg arunppsg merged commit 792210e into deepchem:master Feb 22, 2023
@GreatRSingh GreatRSingh deleted the splitter-docs branch February 24, 2023 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add usage example documentation for splitters
2 participants