Top-level functions and classes¶
sklearn_xarray
-
wrap
(estimator, reshapes=None, sample_dim=None, compat=False, **kwargs)[source]¶ Wrap an sklearn estimator for xarray objects.
- Parameters
- estimatorsklearn estimator class or instance
The estimator this instance wraps around.
- reshapesstr or dict, optional
The dimension(s) reshaped by this estimator. Any coordinates in the DataArray along these dimensions will be dropped. If the estimator drops this dimension (e.g. a binary classifier returning a 1D vector), the dimension itself will also be dropped.
You can specify multiple dimensions mapping to multiple new dimensions with a dict whose items are lists of reshaped dimensions, e.g.
{'new_feature': ['feature_1', 'feature_2'], ...}
- sample_dimstr, optional
The name of the dimension that represents the samples. By default, the wrapper will assume that this is the first dimension in the array.
- compatbool, default False
If True, the method will return a
CompatEstimatorWrapper
instead of anEstimatorWrapper
. This might be necessary when the estimator defines parameters with the same name as the wrapper.
- Returns
- A wrapped estimator.
-
class
EstimatorWrapper
(estimator=None, reshapes=None, sample_dim=None, **kwargs)[source]¶ A wrapper around sklearn estimators compatible with xarray objects.
- Parameters
- estimatorsklearn estimator
The estimator instance this instance wraps around.
- reshapesstr or dict, optional
The dimension(s) reshaped by this estimator. Any coordinates in the DataArray along these dimensions will be dropped. If the estimator drops this dimension (e.g. a binary classifier returning a 1D vector), the dimension itself will also be dropped.
You can specify multiple dimensions mapping to multiple new dimensions with a dict whose items are lists of reshaped dimensions, e.g.
{'new_feature': ['feature_1', 'feature_2'], ...}
- sample_dimstr, optional
The name of the dimension that represents the samples. By default, the wrapper will assume that this is the first dimension in the array.
Methods
fit
(self, X[, y])A wrapper around the fitting function.
get_params
(self[, deep])Get parameters for this estimator.
set_params
(self, **params)Set the parameters of this estimator.
-
fit
(self, X, y=None, **fit_params)[source]¶ A wrapper around the fitting function.
- Parameters
- Xxarray DataArray, Dataset other other array-like
The training input samples.
- yxarray DataArray, Dataset other other array-like
The target values.
- Returns
- Returns self.
-
get_params
(self, deep=True)[source]¶ Get parameters for this estimator.
- Parameters
- deepboolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
- paramsmapping of string to any
Parameter names mapped to their values.
-
set_params
(self, **params)[source]¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.- Returns
- self
-
class
ClassifierWrapper
(estimator=None, reshapes=None, sample_dim=None, **kwargs)[source]¶ A wrapper around sklearn classifiers compatible with xarray objects.
- Parameters
- estimatorsklearn estimator
The estimator this instance wraps around.
- reshapesstr or dict, optional
The dimension reshaped by this estimator.
Methods
fit
(self, X[, y])A wrapper around the fitting function.
get_params
(self[, deep])Get parameters for this estimator.
predict
(self, X)A wrapper around the prediction function.
score
(self, X, y[, sample_weight])Returns the score of the prediction.
set_params
(self, **params)Set the parameters of this estimator.
-
class
RegressorWrapper
(estimator=None, reshapes=None, sample_dim=None, **kwargs)[source]¶ A wrapper around sklearn regressors compatible with xarray objects.
- Parameters
- estimatorsklearn estimator
The estimator this instance wraps around.
- reshapesstr or dict, optional
The dimension reshaped by this estimator.
Methods
fit
(self, X[, y])A wrapper around the fitting function.
get_params
(self[, deep])Get parameters for this estimator.
predict
(self, X)A wrapper around the prediction function.
score
(self, X, y[, sample_weight])Returns the score of the prediction.
set_params
(self, **params)Set the parameters of this estimator.
-
class
TransformerWrapper
(estimator=None, reshapes=None, sample_dim=None, **kwargs)[source]¶ A wrapper around sklearn transformers compatible with xarray objects.
- Parameters
- estimatorsklearn estimator
The estimator this instance wraps around.
- reshapesstr or dict, optional
The dimension reshaped by this estimator.
Methods
fit
(self, X[, y])A wrapper around the fitting function.
fit_transform
(self, X[, y])A wrapper around the fit_transform function.
get_params
(self[, deep])Get parameters for this estimator.
inverse_transform
(self, X)A wrapper around the inverse transformation function.
set_params
(self, **params)Set the parameters of this estimator.
transform
(self, X)A wrapper around the transformation function.
-
class
Target
(coord=None, transform_func=None, transformer=None, lazy=False, dim=None, reduce_func=None)[source]¶ A pointer to xarray coordinates or variables to be used as a target.
- Parameters
- coordstr, optional
The coordinate or variable that holds the data of the target. If not specified, the target will be the entire DataArray/Dataset.
- transform_funccallable, optional
A function that transforms the coordinate values to an sklearn-compatible type and shape. If not specified, the coordinate(s) will be used as-is.
- transformersklearn transformer, optional
Deprecated, use
transform_func=Transformer().fit_transform
instead.- lazybool, optinonal
If true, the target coordinate is only transformed by the transformer when needed. The transformer can implement a
get_transformed_shape
method that returns the shape after the transformation of the provided coordinate without actually transforming the data.- dimstr or sequence of str, optional
When set, multi-dimensional coordinates will be reduced to this dimension/these dimensions.
- reduce_funccallable, optional
A callable that reduces the coordinate(s) to the dimension(s) in
dim
. If not specified, the values along dimensions not indim
will be reduced to the first element in each of these dimensions.
- Attributes
Methods
__call__
(self, X)Call self as a function.
assign_to
(self, X)Assign this target to a DataArray or Dataset.
-
assign_to
(self, X)[source]¶ Assign this target to a DataArray or Dataset.
- Parameters
- Xxarray DataArray or Dataset
The data whose coordinate is used as the target.
- Returns
- self:
The target itself.
-
property
ndim
¶ The number of dimensions of the transformed target.
-
property
shape
¶ The shape of the transformed target.