Views
No views yet
d:/OlympicAI/code/
├── data_preprocessor.py # Text preprocessing utilities
├── models.py # Classification models
├── train_model.py # Main training script
├── requirements.txt # Dependencies
└── README.md # This filepip install -r requirements.txtcomment: Vietnamese text commentsrating: Integer rating from 1-51from train_model import train_and_evaluate_models
2
3# Train all models
4models, results, preprocessor = train_and_evaluate_models('your_data.csv')1from train_model import predict_sentiment
2
3# Predict single comment
4text = "Sản phẩm tuyệt vời, tôi rất hài lòng!"
5rating, confidence = predict_sentiment(
6 text,
7 'model_nb.pkl',
8 'tfidf_vectorizer.pkl'
9)
10print(f"Predicted rating: {rating} stars")Micro-F1 = 2 × Precision × Recall / (Precision + Recall)model_*.pkl: Trained model filestfidf_vectorizer.pkl: Fitted TF-IDF vectorizerconfusion_matrix_*.png: Confusion matrix visualizationsFINAL RESULTS SUMMARY
==================================================
NB | Micro-F1: 0.8234 | Macro-F1: 0.8123 | Weighted-F1: 0.8201
SVM | Micro-F1: 0.8456 | Macro-F1: 0.8334 | Weighted-F1: 0.8423
RF | Micro-F1: 0.8123 | Macro-F1: 0.8001 | Weighted-F1: 0.8089
MLP | Micro-F1: 0.8345 | Macro-F1: 0.8234 | Weighted-F1: 0.8312
LR | Micro-F1: 0.8567 | Macro-F1: 0.8445 | Weighted-F1: 0.8534
ENSEMBLE | Micro-F1: 0.8678 | Macro-F1: 0.8556 | Weighted-F1: 0.8645
Best model: ENSEMBLE with Micro-F1: 0.8678