Binarizer
Module: strata.preprocessing • Kind: struct • Traits: Copyable, Movable, Transformer
Source: strata/preprocessing/binarizer.mojo
struct Binarizer[compute_dtype: DType = DType.float64](Copyable, Movable, Transformer)from strata.preprocessing import BinarizerBinarize feature values according to a threshold.
Values strictly greater than the threshold map to 1, while values less than or equal to the threshold map to 0:
Parameters (Compile-Time)
Section titled “Parameters (Compile-Time)”| Parameter | Description |
|---|---|
compute_dtype |
Computational precision data type. Default DType.float64. |
Constructors
Section titled “Constructors”def __init__(out self, threshold: Scalar[Self.compute_dtype] = 0.0)Initialize the Binarizer.
| Argument | Type | Description |
|---|---|---|
threshold |
Scalar[Self.compute_dtype] |
Feature threshold boundary. Values greater than this map to 1. Default 0.0. |
Attributes
Section titled “Attributes”| Attribute | Description |
|---|---|
n_features_in_ |
Number of features seen during fit. |
is_fitted |
Boolean flag indicating if estimator has been fitted. |
Methods Overview
Section titled “Methods Overview”| Method | Description |
|---|---|
Binarizer.fit() |
Compute fitted parameters from input matrix X. |
Binarizer.transform() |
Transform input features using the fitted parameters. |
Binarizer.fit_transform() |
Fit the estimator to X and return the transformed output. |
Method Details
Section titled “Method Details”Binarizer.fit()
Section titled “Binarizer.fit()”def fit[in_dtype: DType](mut self, X: Matrix[in_dtype])
def fit[feat_dtype: DType, target_dtype: DType]( mut self, dataset: Dataset[feat_dtype, target_dtype],)Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Compute fitted parameters from input matrix X.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Feature matrix. |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
Binarizer.transform()
Section titled “Binarizer.transform()”def transform[in_dtype: DType]( self, X: Matrix[in_dtype],) -> Matrix[in_dtype]
def transform[feat_dtype: DType, target_dtype: DType]( self, dataset: Dataset[feat_dtype, target_dtype],) -> Dataset[ feat_dtype, target_dtype ]Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Transform input features using the fitted parameters.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Feature matrix. |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
Returns: Matrix[in_dtype]
Binarizer.fit_transform()
Section titled “Binarizer.fit_transform()”def fit_transform[in_dtype: DType]( mut self, X: Matrix[in_dtype],) -> Matrix[in_dtype]
def fit_transform[feat_dtype: DType, target_dtype: DType]( mut self, dataset: Dataset[feat_dtype, target_dtype],) -> Dataset[ feat_dtype, target_dtype ]Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Fit the estimator to X and return the transformed output.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Feature matrix. |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
Returns: Matrix[in_dtype]
Section titled “Returns: Matrix[in_dtype]”Example
Section titled “Example”from strata.preprocessing import Binarizerfrom strata.core import Matrix
var binarizer = Binarizer[DType.float64](threshold=0.5)binarizer.fit(X_train)var X_bin = binarizer.transform(X_train)