scikeras.utils.transformers¶
Classes
|
Default target transformer for KerasClassifier. |
Default target transformer for KerasRegressor. |
|
Convert 1D targets to 2D and back. |
- class scikeras.utils.transformers.ClassifierLabelEncoder(loss=None, categories='auto')[source]¶
Default target transformer for KerasClassifier.
- Parameters:
- lossUnion[None, str, Loss], default None
Keras Model’s loss function. Used to automatically one-hot encode the target if the loss function is categorical crossentropy.
- categoriesUnion[str, List[np.ndarray]], default “auto”
All of the categories present in the target for the entire dataset. “auto” will infer the categories from the data passed to fit.
- Attributes:
- classes_Iterable
The classes seen during fit.
- n_classes_int
The number of classes seen during fit.
- n_outputs_int
Dimensions of y that the transformer was trained on.
- n_outputs_expected_int
Number of outputs the Keras Model is expected to have.
- Parameters:
- fit(y)[source]¶
Fit the estimator to the target y.
For all targets, this transforms classes into ordinal numbers. If the loss function is categorical_crossentropy, the target will be one-hot encoded.
- Parameters:
- ynp.ndarray
The target data to be transformed.
- Returns:
- ClassifierLabelEncoder
A reference to the current instance of ClassifierLabelEncoder.
- Parameters:
y (ndarray) –
- Return type:
- fit_transform(X, y=None, **fit_params)[source]¶
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Input samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
- **fit_paramsdict
Additional fit parameters.
- Returns:
- X_newndarray array of shape (n_samples, n_features_new)
Transformed array.
- get_metadata()[source]¶
Returns a dictionary of meta-parameters generated when this transfromer was fitted.
Used by SciKeras to bind these parameters to the SciKeras estimator itself and make them available as inputs to the Keras model.
- get_params(deep=True)[source]¶
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- inverse_transform(y, return_proba=False)[source]¶
Restore the data types, shape and classes of the input y to the output of the Keras Model.
- Parameters:
- ynp.ndarray
Raw probability predictions from the Keras Model.
- return_probabool, default False
If True, return the prediction probabilites themselves. If False, return the class predictions.
- Returns:
- np.ndarray
Class predictions (of the same shape as the y to fit/transform), or class prediction probabilities.
- Parameters:
- Return type:
- set_params(**params)[source]¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- class scikeras.utils.transformers.RegressorTargetEncoder[source]¶
Default target transformer for KerasRegressor.
- Attributes:
- n_outputs_int
Dimensions of y that the transformer was trained on.
- n_outputs_expected_int
Number of outputs the Keras Model is expected to have.
- fit(y)[source]¶
Fit the transformer to the target y.
For RegressorTargetEncoder, this just records the dimensions of y as the expected number of outputs and saves the dtype.
- Returns:
- RegressorTargetEncoder
A reference to the current instance of RegressorTargetEncoder.
- Parameters:
y (ndarray) –
- Return type:
- fit_transform(X, y=None, **fit_params)[source]¶
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Input samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
- **fit_paramsdict
Additional fit parameters.
- Returns:
- X_newndarray array of shape (n_samples, n_features_new)
Transformed array.
- get_metadata()[source]¶
Returns a dictionary of meta-parameters generated when this transfromer was fitted.
Used by SciKeras to bind these parameters to the SciKeras estimator itself and make them available as inputs to the Keras model.
- Returns:
- Dict[str, Any]
Dictionary of meta-parameters generated when this transfromer was fitted.
- get_params(deep=True)[source]¶
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- inverse_transform(y)[source]¶
Restore the data types and shape of the input y to the output of the Keras Model.
- set_params(**params)[source]¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- class scikeras.utils.transformers.TargetReshaper[source]¶
Convert 1D targets to 2D and back.
For use in pipelines with transformers that only accept 2D inputs, like OneHotEncoder and OrdinalEncoder.
- Attributes:
- ndim_int
Dimensions of y that the transformer was trained on.
- fit(y)[source]¶
Fit the transformer to a target y.
- Returns:
- TargetReshaper
A reference to the current instance of TargetReshaper.
- Parameters:
y (ndarray) –
- Return type:
- fit_transform(X, y=None, **fit_params)[source]¶
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Input samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
- **fit_paramsdict
Additional fit parameters.
- Returns:
- X_newndarray array of shape (n_samples, n_features_new)
Transformed array.
- get_params(deep=True)[source]¶
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- set_params(**params)[source]¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.