Skip to main content

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 Int64 data type
    • Output model does not remember which columns should be used

Solution

  • Provide GridSearchCV / RandomizedSearchCV with pandas.DataFrame interface
    • Internally preprocess DataFrame to be applicable for sklearn
  • Output of fit command is now original Model object, which
    • stores column name information
    • provides pandas.DataFrame interface for prediction

Installation

pip install sklearn_cv_pandas

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="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)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sklearn_cv_pandas-0.0.10.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sklearn_cv_pandas-0.0.10-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file sklearn_cv_pandas-0.0.10.tar.gz.

File metadata

  • Download URL: sklearn_cv_pandas-0.0.10.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for sklearn_cv_pandas-0.0.10.tar.gz
Algorithm Hash digest
SHA256 db5f63013ccf03fa7644fa0934b856f955178b7fac97f50675297cd188491b74
MD5 48179154ebd1bf76552052a0a2ff3cd2
BLAKE2b-256 10b65c38142034e6ecdb99904a4cd96c5f0cdbfcdf148749f51dba04b0013d3d

See more details on using hashes here.

File details

Details for the file sklearn_cv_pandas-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for sklearn_cv_pandas-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 a29d9862ebb3558d09a9cc849288a8330a6e97b7b23c2be3e8f9bbef7f85a02a
MD5 4fa83a3fd009da28bfd0b57515c59ef3
BLAKE2b-256 f3f8eab00ec3ba1e8f64f5e56d4800449eb266d70e43e7c94992b75cb3101c6d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.0

2 files

0.0.12

2 files

0.0.11

2 files

This release

0.0.10 This release

2 files

0.0.9

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page