| predict_sentiment | R Documentation |
This is a generic prediction function that handles different model types and ensures consistent preprocessing and vectorization for new, unseen text.
predict_sentiment(pipeline_object, text_column, threshold = 0.5)
pipeline_object |
A list object returned by the main 'pipeline()' function. It must contain the trained model, DFM template, preprocessing function, and n-gram settings. |
text_column |
A string specifying the column name of the text to predict. |
threshold |
Numeric. Optional custom threshold for binary classification. If NULL, uses the optimized threshold from training (if available). |
A data frame containing the 'predicted_class' and probability columns.
if (exists("my_artifacts")) {
dummy_df <- data.frame(text = c("loved it", "hated it"), stringsAsFactors = FALSE)
preds <- predict_sentiment(my_artifacts, df = dummy_df, text_column = "text")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.