pub struct TfIdfVectorizer {
pub min_df: usize,
pub max_df: f64,
pub max_features: Option<usize>,
pub ngram_range: (usize, usize),
pub char_level: bool,
pub case_sensitive: bool,
/* private fields */
}Expand description
TF-IDF (Term Frequency-Inverse Document Frequency) preprocessor
TF-IDF is a numerical statistic that reflects how important a word is to a document in a collection of documents. It increases proportionally to the number of times a word appears in the document but is offset by the frequency of the word in the corpus.
TF-IDF(t,d,D) = TF(t,d) × IDF(t,D)
where:
- TF(t,d) = (Number of times term t appears in document d) / (Total number of terms in d)
- IDF(t,D) = log(Total number of documents / Number of documents containing term t)
Fields§
§min_df: usizeMinimum document frequency (ignore terms that appear in fewer documents)
max_df: f64Maximum document frequency (ignore terms that appear in more documents)
max_features: Option<usize>Maximum number of features
ngram_range: (usize, usize)N-gram range (min_n, max_n)
char_level: boolWhether to use character-level n-grams
case_sensitive: boolCase sensitivity
Implementations§
Source§impl TfIdfVectorizer
impl TfIdfVectorizer
Sourcepub fn with_min_df(self, min_df: usize) -> Self
pub fn with_min_df(self, min_df: usize) -> Self
Set minimum document frequency
Sourcepub fn with_max_df(self, max_df: f64) -> Self
pub fn with_max_df(self, max_df: f64) -> Self
Set maximum document frequency
Sourcepub fn with_max_features(self, max_features: Option<usize>) -> Self
pub fn with_max_features(self, max_features: Option<usize>) -> Self
Set maximum features
Sourcepub fn with_ngram_range(self, min_n: usize, max_n: usize) -> Self
pub fn with_ngram_range(self, min_n: usize, max_n: usize) -> Self
Set n-gram range
Sourcepub fn with_char_level(self, char_level: bool) -> Self
pub fn with_char_level(self, char_level: bool) -> Self
Set character level
Sourcepub fn with_case_sensitive(self, case_sensitive: bool) -> Self
pub fn with_case_sensitive(self, case_sensitive: bool) -> Self
Set case sensitivity
Sourcepub fn transform(&self, documents: &[String]) -> Result<Array2<f64>>
pub fn transform(&self, documents: &[String]) -> Result<Array2<f64>>
Transform documents to TF-IDF matrix
Sourcepub fn fit_transform(&mut self, documents: &[String]) -> Result<Array2<f64>>
pub fn fit_transform(&mut self, documents: &[String]) -> Result<Array2<f64>>
Fit and transform in one step
Sourcepub fn get_feature_names(&self) -> Result<Vec<String>>
pub fn get_feature_names(&self) -> Result<Vec<String>>
Get feature names
Trait Implementations§
Source§impl Clone for TfIdfVectorizer
impl Clone for TfIdfVectorizer
Source§fn clone(&self) -> TfIdfVectorizer
fn clone(&self) -> TfIdfVectorizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TfIdfVectorizer
impl Debug for TfIdfVectorizer
Auto Trait Implementations§
impl Freeze for TfIdfVectorizer
impl RefUnwindSafe for TfIdfVectorizer
impl Send for TfIdfVectorizer
impl Sync for TfIdfVectorizer
impl Unpin for TfIdfVectorizer
impl UnsafeUnpin for TfIdfVectorizer
impl UnwindSafe for TfIdfVectorizer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more