1import joblib
23# Load model4model = joblib.load('tfidf_logreg.joblib')56# Make prediction7review =['Produk sangat bagus dan cepat sampai!']8prediction = model.predict(review)9confidence = model.predict_proba(review)1011labels ={0:'Negatif',1:'Netral',2:'Positif'}12print(f"Sentiment: {labels[prediction[0]]}")13print(f"Confidence: {confidence[0].max():.2%}")
Load SVM Model
python
1import joblib
23# Load SVM model4model = joblib.load('tfidf_svm.joblib')56# Make prediction7prediction = model.predict(['Barang rusak, tidak puas'])8probabilities = model.decision_function(['Barang rusak, tidak puas'])910labels ={0:'Negatif',1:'Netral',2:'Positif'}11print(f"Predicted: {labels[prediction[0]]}")
Load Naive Bayes Model
python
1import joblib
23# Load NB model4model = joblib.load('tfidf_nb.joblib')56# Make prediction (Naive Bayes has probabilistic outputs)7prediction = model.predict(['Produk OK, sesuai harga'])8probabilities = model.predict_proba(['Produk OK, sesuai harga'])910labels ={0:'Negatif',1:'Netral',2:'Positif'}11print(f"Sentiment: {labels[prediction[0]]}")12print(f"Class Probabilities: {dict(zip(labels.values(), probabilities[0]))}")
Batch Processing
python
1import joblib
23model = joblib.load('tfidf_svm.joblib')# Use best model (SVM)45reviews =[6'Produk bagus, recommend!',7'Lumayan lah',8'Jelek banget, mau komplain'9]1011predictions = model.predict(reviews)12labels ={0:'Negatif',1:'Netral',2:'Positif'}1314for review, pred inzip(reviews, predictions):15print(f"'{review}' → {labels[pred]}")
✨ Advantages
✅ Fast Inference - 5-15ms per sample on CPU
✅ Small Model Size - Only ~1.2-1.5 MB each (vs 475 MB for transformer)
✅ No GPU Required - Works on any CPU-only systems
✅ Interpretable - Can extract feature importance (LR, NB)
✅ Production-Ready - Easy deployment and ONNX conversion
✅ High Accuracy - 97.60% for SVM model
✅ Multiple Options - Choose based on speed vs accuracy trade-off
📊 Model Comparison
Aspect
LogReg
SVM
NB
IndoBERT
Accuracy
94.36%
97.60%
97.53%
88.70%
Macro F1
0.5164
0.5506
0.3292
0.5088
Inference Speed
~10ms
~15ms
~5ms
~500ms
Model Size
1.2MB
1.5MB
1.2MB
475MB
GPU Required
❌
❌
❌
❌*
Interpretable
✅ High
⚠️ Medium
✅ High
❌ Low
Semantic Understanding
❌ Low
❌ Low
❌ Low
✅ High
*IndoBERT without GPU is very slow (~1-2s per sample)
Recommendation by Use Case
Production Deployment: Use SVM (best accuracy + reasonable speed)
Real-time Requirements: Use Naive Bayes (fastest inference)
Explainability Needed: Use Logistic Regression (most interpretable)
Complex Semantics: Use IndoBERT (see separate model)
⚙️ Training Configuration
Vectorization
Parameter
Value
Vectorizer
TfidfVectorizer
Min DF (minimum document frequency)
1
Max DF (maximum document frequency)
1.0
Max Features
100,000
Norm
L2
Sublinear TF
True
Word N-grams
(1, 3)
Char N-grams
(2, 4)
Logistic Regression
Parameter
Value
Max Iterations
2000
Regularization
L2
C (regularization strength)
0.5
Class Weight
balanced
Solver
lbfgs
Support Vector Machine
Parameter
Value
Kernel
linear
C (regularization strength)
0.5
Class Weight
balanced
Dual
False
Max Iterations
1000
Naive Bayes
Parameter
Value
Alpha (Laplace smoothing)
1.0
Fit Prior
True
Class Prior
None (automatic)
Dataset Information
Source: Tokopedia Product Reviews 2025
Total Samples: 65,335
Train/Test Split: 80/20 (stratified)
Languages: Indonesian
Domain: E-commerce product sentiment
Train Set: 52,268 samples
Test Set: 13,067 samples
Limitations
May struggle with sarcasm or complex linguistic patterns
Recommendation: For production systems with CPU constraints, use this baseline model. For deeper semantic understanding and edge cases, combine with IndoBERT model for ensemble predictions.