Model Selection

sklearn_xarray.model_selection

class CrossValidatorWrapper(cross_validator, dim='sample', groupby=None)[source]

Wrap an sklearn cross validator for use with xarray.

Parameters
cross_validatorsklearn cross-validator

An instance of a cross-validator.

dimstr

The dimension along which to perform the split.

groupbystr or list

Name of coordinate or list of coordinates by which the groups are determined.

Methods

get_n_splits(self[, X, y, groups])

Returns the number of splitting iterations in the cross-validator.

split(self, X[, y, groups])

Generate indices to split data into training and test set.

get_n_splits(self, X=None, y=None, groups=None)[source]

Returns the number of splitting iterations in the cross-validator.

Parameters
Xobject

Always ignored, exists for compatibility.

yobject

Always ignored, exists for compatibility.

groupsobject

Always ignored, exists for compatibility.

Returns
n_splitsint

Returns the number of splitting iterations in the cross-validator.

split(self, X, y=None, groups=None)[source]

Generate indices to split data into training and test set.

Parameters
Xxarray DataArray or Dataset

Training data, where n_samples is the number of samples and n_features is the number of features.

yarray-like, shape (n_samples,)

The target variable for supervised learning problems.

groupsarray-like, with shape (n_samples,), optional

Group labels for the samples used while splitting the dataset into train/test set.

Returns
trainndarray

The training set indices for that split.

testndarray

The testing set indices for that split.