a more in-depth testsplit splitting intercategorical
Project description
fancy schmancy testsplit
it's like a testsplit, but fancy and also schmancy
for reference:
| package | fancy | schmancy | testsplit |
|---|---|---|---|
| sklearn.model_selection | ❎ | ❎ | ✅ |
| fancy schmancy testsplit | ✅ | ✅ | ✅ |
thumbsup: 👍 thumbsdown: 👎
a testplit per label category, to ensure that every category is present
Examples
Assume the following DataFrame:
df = DataFrame(data= {"Column A":[10, 14, 12, 13, 9, 5, 13, 16, 18, 4, 12],
"Column B": ["Cat1", "Cat1", "Cat2", "Cat2", "Cat2", "Cat2", "Cat2", "Cat2", "Cat2", "Cat2", "Cat2"]})
print(df)
| Column A | Column B | |
|---|---|---|
| 0 | 10 | Cat1 |
| 1 | 14 | Cat1 |
| 2 | 12 | Cat2 |
| 3 | 13 | Cat2 |
| 4 | 9 | Cat2 |
| 5 | 5 | Cat2 |
| 6 | 13 | Cat2 |
| 7 | 16 | Cat2 |
| 8 | 18 | Cat2 |
| 9 | 4 | Cat2 |
| 10 | 12 | Cat2 |
If we assume further that Column B contains the label categories, we'd run the risk of eliminating Cat1 by doing a train test split at 50%.
So, to preserve every existing category, the split will instead be made on every single subset of categories.
As an example for Cat1:
subset = df[df["Column B"] == "Cat1"]
X = subset.drop("Column B", axis= 1)
y = subset["Column B"]
if isinstance(y, Series): y = DataFrame(y)
X_tr, X_te, y_tr, y_te = \
train_test_split(X, y, test_size = 0.5, random_state = 42)
print(y_tr)
| Column B | |
|---|---|
| 0 | Cat1 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file FancySchmancyTestsplit-0.1.2.tar.gz.
File metadata
- Download URL: FancySchmancyTestsplit-0.1.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a355ffa26e63e2de5d221aec43f85c34edc2b19f1697a524d36cf417f632fe24
|
|
| MD5 |
789061c837f2cf0a2e445866fe499a6f
|
|
| BLAKE2b-256 |
43ec1959b6b9c543bfb60c9c927edebcc28269a0f9a142b13c57c7ccffcf4734
|
File details
Details for the file FancySchmancyTestsplit-0.1.2-py3-none-any.whl.
File metadata
- Download URL: FancySchmancyTestsplit-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9d852957c17ae6aae19ae6ec07e4dcbd8c9cc7424db72b2917f0c775bcae6ac
|
|
| MD5 |
142055eb8cd95d5291c5f91c27f035bc
|
|
| BLAKE2b-256 |
bd74bd094d858cd568c862e2c2bbf5a04c73fb659df638968b261347823f8401
|