sklearn-cv-pandas
RandomizedSearchCV/GridSearchCV with pandas.DataFrame interface
Why do I want this?
- I usually prepare features as pandas.DataFrame
- Scikit learn input should be
array-like. https://scikit-learn.org/stable/glossary.html#term-array-like. - Although it includes pandas.DataFrame, there are some issues;
- It does not support
Int64data type - Output model does not remember which columns should be used
- It does not support
Solution
- Provide GridSearchCV / RandomizedSearchCV with pandas.DataFrame interface
- Internally preprocess DataFrame to be applicable for sklearn
- Output of
fitcommand is now originalModelobject, which- stores column name information
- provides pandas.DataFrame interface for prediction
Installation
pip install sklearn_cv_pandas
Development
Requires Python 3.11+ and uv.
uv sync --group dev
uv run pytest
Usage
Configure CV object
Instantiate CV in the same manner as original ones.
from scipy import stats
from sklearn import linear_model
from sklearn_cv_pandas import RandomizedSearchCV
estimator = linear_model.Lasso()
param_dist = dict(alpha=stats.loguniform(1e-5, 10))
cv = RandomizedSearchCV(estimator, param_dist, scoring="neg_mean_absolute_error")
fit with pandas.DataFrame
Our CV object has new methods fit_holdout_pandas and fit_cv_pandas.
Original ones requires x and y as numpy.array.
Instead of numpy array, you can specify one pandas.DataFrame
and column names for x (feature_columns), and column name of y (target_column).
model = cv.fit_cv_pandas(
df, target_column="y", feature_columns=["x{}".format(i) for i in range(100)], n_fold=5
)
predict with pandas.DataFrame
You can run prediction with pandas.DataFrame interface as well.
Output of fit_holdout_pandas and fit_cv_pandas stores feature_columns and target_column.
You can just input pandas.DataFrame for prediction into the method predict.
model.predict(df)
Metadata
Release files for sklearn_cv_pandas 0.1.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 | Provenance | Actions |
|---|---|---|---|---|
| sklearn_cv_pandas-0.1.0.tar.gz | 8.5 kB | Without provenance | Details for sklearn_cv_pandas-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sklearn_cv_pandas-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sklearn_cv_pandas-0.1.0-py3-none-any.whl |
Total release size: 15.6 kB
Release files / sklearn_cv_pandas-0.1.0.tar.gz
| Download URL | sklearn_cv_pandas-0.1.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9579c9a408a885f247cc39dc0270b9b80d5cb32e245c66676bffa160a348f699
|
|
BLAKE2b-256 checksum How to use checksums |
ef7def7a4ccf53fab1b58327f4bc394759f616d4a8bc1308cca2db24167f45b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / sklearn_cv_pandas-0.1.0-py3-none-any.whl
| Download URL | sklearn_cv_pandas-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6db3a474036b7ac1eae8285f40b29bfe8d0772e2085826919e283893cacfb153
|
|
BLAKE2b-256 checksum How to use checksums |
3ad2b35d2f6132fc3b2064c4a6f92b4835e88425f27e42791ef61c1c82ef871d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for sklearn_cv_pandas 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.