Chain#
- class ray.data.preprocessors.Chain(*preprocessors: SerializablePreprocessorBase)[source]#
Bases:
SerializablePreprocessorBaseCombine multiple preprocessors into a single
Preprocessor.When you call
fit, each preprocessor is fit on the dataset produced by the preceeding preprocessor’sfit_transform.When
DataContext.enable_aggregation_based_preprocessorsis set and every fittable member supports it,fitinstead only registers each member’s statistics as aggregation queries; the firsttransform()(ortransform_batch(), or serialization) computes them over the fit dataset, batching independent members’ aggregations into a single dataset scan per dependency level. The fitted statistics are identical either way.Deferred fitting relies on each member’s declared input and output columns: a member that declares both is assumed to change only those columns, row by row. A member that adds or drops rows (for example, a user-defined preprocessor that filters out nulls) must not declare both; such members are treated as reading and writing every column, so the members around them fit in chain order.
Example
>>> import pandas as pd >>> import ray >>> from ray.data.preprocessors import * >>> >>> df = pd.DataFrame({ ... "X0": [0, 1, 2], ... "X1": [3, 4, 5], ... "Y": ["orange", "blue", "orange"], ... }) >>> ds = ray.data.from_pandas(df) >>> >>> preprocessor = Chain( ... StandardScaler(columns=["X0", "X1"]), ... Concatenator(columns=["X0", "X1"], output_column_name="X"), ... LabelEncoder(label_column="Y") ... ) >>> preprocessor.fit_transform(ds).to_pandas() Y X 0 1 [-1.224744871391589, -1.224744871391589] 1 0 [0.0, 0.0] 2 1 [1.224744871391589, 1.224744871391589]
- Parameters:
*preprocessors (SerializablePreprocessorBase) – The preprocessors to sequentially compose.
Methods
Deserialize a preprocessor from serialized data.
Fit this Preprocessor to the Dataset.
Get the preprocessor class identifier for this preprocessor class.
Get the version number for this preprocessor class.
Batch format hint for upstream producers to try yielding best block format.
Serialize this preprocessor to a string or bytes.
Set the preprocessor class identifier for this preprocessor class.
Set the version number for this preprocessor class.
Transform the given dataset.
Transform a single batch of data.
Attributes