skoot.preprocessing
.SchemaNormalizer¶
-
class
skoot.preprocessing.
SchemaNormalizer
(schema)[source][source]¶ Enforce a schema on an input dataframe.
The SchemaNormalizer enforces a schema across incoming train and test data. This ensures that all data matches the expected schema. Note that unlike most other Skoot transformers, this one requires that the output be a DataFrame (note the lack of the
as_df
constructor arg).Parameters: schema : dict
The schema. This dictionary maps column names to actions. For instance the following schema will cast the iris dataset “petal widtch (cm)” column to integer:
>>> schema = {'petal width (cm)': int}
Attributes
fit_cols_ (list) The list of column names on which the transformer was fit. This is used to validate the presence of the features in the test set during the transform
stage.Methods
fit
(X[, y])Fit the transformer. fit_transform
(X[, y])Fit to data, then transform it. get_params
([deep])Get parameters for this estimator. set_params
(**params)Set the parameters of this estimator. transform
(X)Apply the schema normalization. -
fit
(X, y=None)[source][source]¶ Fit the transformer.
Default behavior is not to fit any parameters and return self. This is useful for transformers which do not require parameterization, but need to fit into a pipeline.
Parameters: X : pd.DataFrame, shape=(n_samples, n_features)
The Pandas frame to fit.
y : array-like or None, shape=(n_samples,), optional (default=None)
Pass-through for
sklearn.pipeline.Pipeline
.
-
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: X : numpy array of shape [n_samples, n_features]
Training set.
y : numpy array of shape [n_samples]
Target values.
Returns: X_new : numpy array of shape [n_samples, n_features_new]
Transformed array.
-
get_params
(deep=True)[source]¶ Get parameters for this estimator.
Parameters: deep : boolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: params : mapping of string to any
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 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
-
transform
(X)[source][source]¶ Apply the schema normalization.
Parameters: X : pd.DataFrame, shape=(n_samples, n_features)
The Pandas frame to transform. The operation will be applied to a copy of the input data, and the result will be returned.
Returns: X : pd.DataFrame or np.ndarray, shape=(n_samples, n_features)
The operation is applied to a copy of
X
, and the result set is returned.
-