-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
@gusty1g sir, check the example for MolecularWeightSplitter. |
deepchem/splits/splitters.py
Outdated
>>> 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
deepchem/splits/splitters.py
Outdated
>>> 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) |
There was a problem hiding this comment.
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.
@gusty1g can you suggest example for RandomGroupSplitter. I am having difficulty in making example for it. |
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 |
Pull Request Template
Description
Fix #3230
This PR aims to add example documentation for Splitters.
Type of change
Please check the option that is related to your PR.
Checklist
yapf -i <modified file>
and check no errors (yapf version must be 0.32.0)mypy -p deepchem
and check no errorsflake8 <modified file> --count
and check no errorspython -m doctest <modified file>
and check no errors