Description Usage Format Usage Methods Examples
Provides an easy way to create tf-idf matrix of features in R. It consists of fit, transform methods (similar to sklearn) to generate tf-idf features.
1 |
R6Class
object.
For usage details see Methods, Arguments and Examples sections.
1 2 3 4 | tf_object = TfIdfVectorizer$new(max_df=1, min_df=1, max_features=1, smooth_idf=TRUE)
tf_object$fit(sentences)
tf_matrix = tf_object$transform(sentences)
tf_matrix = tf_object$fit_transform(sentences) ## alternate
|
$new()
Initialise the instance of the vectorizer
$fit()
creates a memory of count vectorizers but doesn't return anything
$transform()
based on encodings learned in fit
method, returns the tf-idf matrix
$fit_transform()
returns tf-idf matrix
1 2 3 4 5 6 | df <- data.frame(sents = c('i am alone in dark.',
'mother_mary a lot',
'alone in the dark?',
'many mothers in the lot....'))
tf <- TfIdfVectorizer$new(smooth_idf = TRUE, min_df = 0.3)
tf_features <- tf$fit_transform(df$sents)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.