## Loading required package: foreach
## Loading required package: iterators
## Loading required package: parallel
## quickSentiment: Retaining negation words (e.g., 'not', 'no', 'never') to preserve sentiment polarity. To apply the strict stopword list instead, set `retain_negations = FALSE`. View qs_negations for more
result <- pipeline(
# --- Define the vectorization method ---
# Options: "bow" (raw counts), "tf" (term frequency), "tfidf", "binary"
vect_method = "tf",
# --- Define the model to train ---
# Options: "logit", "rf", "xgb","nb"
model_name = "rf",
# --- Specify the data and column names ---
text_vector = tweets$cleaned_text , # The column with our preprocessed text
sentiment_vector = tweets$sentiment, # The column with the target variable
# --- Set vectorization options ---
# Use n_gram = 2 for unigrams + bigrams, or 1 for just unigrams
#these are optional parameters
balance = TRUE,
n_gram = 1,
parallel = cores
)## --- Running Pipeline: TERM_FREQUENCY + RANDOM_FOREST ---
## Data split: 944 training elements, 237 test elements.
## Vectorizing with TERM_FREQUENCY (ngram=1)...
## - Fitting BoW model (term_frequency) on training data...
## - Applying BoW transformation (term_frequency) to new data...
##
## --- Training Random Forest Model (ranger) ---
## --- Random Forest complete. Returning results. ---
##
## ======================================================
## --- quickSentiment Pipeline Complete ---
## Model Type: RANDOM_FOREST
## Vectorizer: TERM_FREQUENCY (ngram=1)
## Test Set Size: 237 rows
## Accuracy of 71.31% under baseline threshold.
## ======================================================
## =========================================
## quickSentiment Model Evaluation
## =========================================
## Target Class: P
##
## --- Global Metrics ---
## ROC AUC: 0.706
## PR AUC: 0.4443
##
## --- Optimal Thresholds ---
## Best ROC Threshold (Youden's J): 0.39
## Best PR Threshold (F1-Score): 0.39
## Accuracy at Best PR Threshold: 0.6498
##
## --- Threshold Summary Table ---
## Threshold Accuracy Precision Recall F1
## 0.0 0.257 0.257 1.000 0.409
## 0.1 0.384 0.286 0.934 0.438
## 0.2 0.494 0.325 0.902 0.478
## 0.3 0.570 0.344 0.738 0.469
## 0.4 0.646 0.388 0.656 0.488
## 0.5 0.713 0.441 0.426 0.433
## 0.6 0.755 0.545 0.295 0.383
## 0.7 0.755 0.588 0.164 0.256
## 0.8 0.747 0.667 0.033 0.062
## 0.9 0.743 0.000 0.000 0.000
## 1.0 0.743 0.000 0.000 0.000
##
## (Note: Use plot() to view ROC and PR curves)
# =================================================================== #
— 6. PREDICTION ON NEW, UNSEEN DATA — #
=================================================================== ##
The training is complete. The ‘result’ object now contains our trained
## model and all the necessary “artifacts” for prediction.
## --- Preparing new data for prediction ---
## - Applying BoW transformation (term_frequency) to new data...
## --- Making Predictions ---
## --- Prediction Complete ---
## predicted_class prob_N prob_P
## 1 P 0.1842199 0.8157801
## 2 P 0.1178659 0.8821341
## 3 P 0.2181332 0.7818668
## 4 P 0.1382764 0.8617236
## 5 P 0.1271654 0.8728346
## 6 P 0.1220916 0.8779084