File size: 3,057 Bytes
6acb9b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0db2f3
6acb9b8
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
language: pt
tags:
- sentiment-analysis
- text-classification
- scikit-learn
- tf-idf
- logistic-regression
metrics:
- accuracy
- precision
- recall
- f1
---

# FoodReviewAI - Restaurant Review Sentiment Classifier

## Model Description

FoodReviewAI is a machine learning model developed to classify restaurant reviews written in Portuguese as positive or negative.

The project demonstrates a complete machine learning workflow, including data preprocessing, model training, evaluation, and API integration.

## Model Architecture

- **Text representation:** TF-IDF (maximum 10,000 features, unigrams and bigrams)
- **Classification algorithm:** Logistic Regression
- **Class balancing:** `class_weight="balanced"`
- **Framework:** scikit-learn

## Training Data

The model was trained using the StarRest dataset, containing reviews of Brazilian restaurants.

After preprocessing, 16,293 Portuguese reviews were selected:

- 15,207 positive reviews
- 1,086 negative reviews

Only reviews from platforms 1, 2, and 3 were used.

Reviews rated 1 or 2 were labeled negative, while reviews rated 4 or 5 were labeled positive. Reviews rated 3 were excluded.

## Evaluation Results

The dataset was split into 80% training and 20% testing, using stratified sampling.

| Metric | Result |
|---|---|
| Accuracy | 95.6% |
| Negative precision | 0.61 |
| Negative recall | 0.91 |
| Negative F1-score | 0.73 |
| Positive F1-score | 0.98 |

### Confusion Matrix

| | Predicted Negative | Predicted Positive |
|---|---|---|
| Actual Negative | 198 | 19 |
| Actual Positive | 125 | 2917 |

## Usage

Install the required libraries:

```bash
pip install scikit-learn joblib huggingface_hub
```

Download and load the trained model:

```python
from huggingface_hub import hf_hub_download
import joblib

caminho = hf_hub_download(
    repo_id="felipermtrindade/FoodReviewAI-Sentiment",
    filename="foodreview_model.pkl"
)

modelo = joblib.load(caminho)

texto = ["A comida estava maravilhosa e o atendimento foi excelente!"]

resultado = modelo.predict(texto)

print("Positiva" if resultado[0] == 1 else "Negativa")
```

Only load this model file if you trust its publisher. Joblib files use Python serialization and can execute code when loaded.

## Limitations

- The dataset is highly imbalanced, with approximately 93% positive reviews.
- The model performs binary classification and may struggle with mixed or neutral sentiments.
- Sentiment labels were derived from customer ratings, not manually annotated.
- The model was trained using Portuguese restaurant reviews and may not generalize to other domains.
- Predicted probabilities have not been independently calibrated.

## Source Code

[FoodReviewAI on GitHub](https://github.com/felipemtrindade/FoodReviewAI)

## Dataset

[StarRest - Mendeley Data](https://data.mendeley.com/datasets/r5th4s7vpv/2)

## Future Improvements

- Compare performance against Portuguese BERT models.
- Evaluate errors and ambiguous reviews.
- Improve minority-class classification.
- Add automated testing and model versioning.