pub struct Binarizer<F> { /* private fields */ }Expand description
A stateless feature binarizer.
Values strictly greater than threshold become 1.0; all other values
become 0.0. The default threshold is 0.0.
This transformer is stateless — no fitting is needed. Call
Transform::transform directly.
§Examples
use ferrolearn_preprocess::binarizer::Binarizer;
use ferrolearn_core::traits::Transform;
use ndarray::array;
let binarizer = Binarizer::<f64>::new(0.5);
let x = array![[0.0, 0.5, 1.0]];
let out = binarizer.transform(&x).unwrap();
// out = [[0.0, 0.0, 1.0]]Implementations§
Source§impl<F: Float + Send + Sync + 'static> Binarizer<F>
impl<F: Float + Send + Sync + 'static> Binarizer<F>
Sourcepub fn new(threshold: F) -> Self
pub fn new(threshold: F) -> Self
Create a new Binarizer with the given threshold (and the default
copy = true).
sklearn constrains threshold to Interval(Real, None, None, closed="neither") on binarize (_data.py:2114-2115) — an OPEN
interval (-inf, inf) that EXCLUDES NaN/±inf. A non-finite threshold
is NOT rejected by new (no validation at construction, matching
sklearn’s __init__, which stores params unchecked); it is rejected
later by Fit::fit / Transform::transform / binarize
(InvalidParameter), matching sklearn’s _fit_context /
@validate_params raising InvalidParameterError at fit/binarize.
Sourcepub fn with_copy(self, copy: bool) -> Self
pub fn with_copy(self, copy: bool) -> Self
Set the copy parameter (sklearn Binarizer(copy=...),
_data.py:2253, _parameter_constraints {copy:["boolean"]} :2250).
This is an ACCEPT-AND-DOCUMENT no-op: ferrolearn’s Transform always
returns a freshly allocated array, so copy has no observable effect on
the output. It is retained for API parity with scikit-learn.
Trait Implementations§
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for Binarizer<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for Binarizer<F>
Source§fn fit(&self, x: &Array2<F>, _y: &()) -> Result<FittedBinarizer<F>, FerroError>
fn fit(&self, x: &Array2<F>, _y: &()) -> Result<FittedBinarizer<F>, FerroError>
Validate the input and record n_features_in_, returning a
FittedBinarizer.
Binarizer is stateless: like scikit-learn’s Binarizer.fit
(sklearn/preprocessing/_data.py:2257-2278, “Only validates estimator’s
parameters”), this learns NO statistics. It runs the SAME check_array
validation as Transform::transform / binarize (REQ-9, via the
shared [validate_binarize_input] helper) and records
n_features_in_ = x.ncols(). sklearn’s _validate_data uses the default
force_all_finite=True, so NaN/±inf are REJECTED in fit
(Binarizer().fit([[nan]]) / [[inf]] raise ValueError). sklearn’s
_fit_context validates _parameter_constraints (:2249) BEFORE the
data, and threshold is constrained to Interval(Real, None, None, closed="neither") on binarize (_data.py:2114) — an OPEN interval
(-inf, inf) that EXCLUDES NaN/±inf. A non-finite threshold is
therefore rejected here (param-check first, matching _fit_context).
§Errors
Returns FerroError::InvalidParameter if threshold is non-finite
(NaN/±inf, sklearn Interval(Real, None, None, closed="neither"),
_data.py:2114), FerroError::InsufficientSamples for zero rows, and
FerroError::InvalidParameter for zero features or any non-finite
value (NaN, +inf, -inf) — matching check_array
(sklearn/utils/validation.py:1084, :1093, :1063) as routed through
Binarizer.fit -> _validate_data (_data.py:2277).
Source§type Fitted = FittedBinarizer<F>
type Fitted = FittedBinarizer<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for Binarizer<F>
impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for Binarizer<F>
Source§fn transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Apply the threshold: values > threshold become 1.0, others become 0.0.
§Errors
Returns FerroError::InsufficientSamples if x has zero rows. This
mirrors scikit-learn’s Binarizer.transform
(sklearn/preprocessing/_data.py:2301), whose _validate_data ->
check_array min-samples check raises ValueError: Found array with 0 sample(s) ... while a minimum of 1 is required by Binarizer.
Returns FerroError::InvalidParameter if x has zero features
(columns). This mirrors scikit-learn’s Binarizer.transform
(sklearn/preprocessing/_data.py:2301), whose _validate_data ->
check_array min-features check (utils/validation.py:1093,
ensure_min_features=1) raises ValueError: Found array with 0 feature(s) (shape=(3, 0)) while a minimum of 1 is required by Binarizer.
Returns FerroError::InvalidParameter if x contains any non-finite
value (NaN, +inf, or -inf). This mirrors scikit-learn’s
Binarizer.transform (sklearn/preprocessing/_data.py:2301), which
validates input via check_array(force_all_finite=True) and raises
ValueError: Input X contains NaN. / Input X contains infinity ...
before applying the threshold comparison.
Source§type Error = FerroError
type Error = FerroError
transform.Auto Trait Implementations§
impl<F> Freeze for Binarizer<F>where
F: Freeze,
impl<F> RefUnwindSafe for Binarizer<F>where
F: RefUnwindSafe,
impl<F> Send for Binarizer<F>where
F: Send,
impl<F> Sync for Binarizer<F>where
F: Sync,
impl<F> Unpin for Binarizer<F>where
F: Unpin,
impl<F> UnsafeUnpin for Binarizer<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for Binarizer<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.