pub struct TfidfTransformer<F> {
pub norm: TfidfNorm,
pub use_idf: bool,
pub smooth_idf: bool,
pub sublinear_tf: bool,
/* private fields */
}Expand description
An unfitted TF-IDF transformer.
Fits IDF weights from a term-count matrix and transforms new count matrices into TF-IDF weighted matrices.
§Examples
use ferrolearn_preprocess::tfidf::{TfidfTransformer, TfidfNorm};
use ndarray::array;
let counts = array![
[3.0_f64, 0.0, 1.0],
[2.0, 0.0, 0.0],
[3.0, 0.0, 0.0],
[4.0, 0.0, 0.0],
[3.0, 2.0, 0.0],
[3.0, 0.0, 2.0],
];
let tfidf = TfidfTransformer::<f64>::new();
let fitted = tfidf.fit(&counts).unwrap();
let result = fitted.transform(&counts).unwrap();
assert_eq!(result.shape(), counts.shape());Fields§
§norm: TfidfNormRow normalization mode.
use_idf: boolWhether to use IDF weighting.
smooth_idf: boolWhether to smooth IDF: ln((1+n)/(1+df)) + 1.
sublinear_tf: boolWhether to apply sublinear TF scaling: 1 + ln(tf).
Implementations§
Source§impl<F: Float + Send + Sync + 'static> TfidfTransformer<F>
impl<F: Float + Send + Sync + 'static> TfidfTransformer<F>
Sourcepub fn smooth_idf(self, smooth: bool) -> Self
pub fn smooth_idf(self, smooth: bool) -> Self
Set whether to smooth IDF.
Sourcepub fn sublinear_tf(self, sublinear: bool) -> Self
pub fn sublinear_tf(self, sublinear: bool) -> Self
Set whether to apply sublinear TF scaling.
Sourcepub fn fit(
&self,
counts: &Array2<F>,
) -> Result<FittedTfidfTransformer<F>, FerroError>
pub fn fit( &self, counts: &Array2<F>, ) -> Result<FittedTfidfTransformer<F>, FerroError>
Fit the transformer by computing IDF from a term-count matrix.
§Errors
Returns FerroError::InsufficientSamples if the matrix has zero rows.
Trait Implementations§
Source§impl<F: Clone> Clone for TfidfTransformer<F>
impl<F: Clone> Clone for TfidfTransformer<F>
Source§fn clone(&self) -> TfidfTransformer<F>
fn clone(&self) -> TfidfTransformer<F>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<F: Debug> Debug for TfidfTransformer<F>
impl<F: Debug> Debug for TfidfTransformer<F>
Auto Trait Implementations§
impl<F> Freeze for TfidfTransformer<F>
impl<F> RefUnwindSafe for TfidfTransformer<F>where
F: RefUnwindSafe,
impl<F> Send for TfidfTransformer<F>where
F: Send,
impl<F> Sync for TfidfTransformer<F>where
F: Sync,
impl<F> Unpin for TfidfTransformer<F>where
F: Unpin,
impl<F> UnsafeUnpin for TfidfTransformer<F>
impl<F> UnwindSafe for TfidfTransformer<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
Mutably borrows from an owned value. Read more
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,
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>
Converts
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>
Converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.