Sentiment.mp4
This project aims to build an end-to-end sentiment analysis solution that can extract, preprocess, analyze, and visualize customer sentiment from textual reviews. This solution will provide valuable insights to our business stakeholders, empowering them to make data-driven decisions and enhance the overall customer experience.
- Clone the repository:
git clone https://github.com/GogoHarry/product-review-sentiment.git cd product-review-sentiment - Create a virtual environment:
python -m sentiment_analysis_venv
- Activate the virtual environment:
- On Windows:
sentiment_analysis_venv\Scripts\activate
- On macOS/Linux:
source sentiment_analysis_venv/bin/activate
- On Windows:
- Install the dependencies:
pip install -r requirements.txt
-
Train the model and save the preprocessor and model:
-
Run the Streamlit web application:
streamlit run app.py
- Predict the sentiment behind a review based on the review text
- Preprocess data using the preprocessing function
- Web interface for user-friendly interaction.
- Preprocess data using the preprocessing function and save it
- Vectorize the preprocessed data using TF-IDF vectorization and save the vectorizer
- Train the Support Vector Machine model and save the model.
Evaluate the model using accuracy_score, f1_score, and precision_score
from sklearn.metrics import accuracy_score, precision_score, f1_score, classification_report, confusion_matrix
# Evaluation metrics
accuracy = accuracy_score(y_test, svc_y_pred)
precision = precision_score(y_test, svc_y_pred, average='weighted')
f1 = f1_score(y_test, svc_y_pred, average='weighted')
print(f"Accuracy: {accuracy:.4f}")
print(f"Precision: {precision:.4f}")
print(f"F1-Score: {f1:.4f}")
# Classification report
print("\nClassification Report:")
print(classification_report(y_test, svc_y_pred))
# Compute the confusion matrix
cm = confusion_matrix(y_test, svc_y_pred)
# Plot the heatmap
plt.figure(figsize=(8, 6))
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', cbar=False,
xticklabels=['Negative', 'Positive'], yticklabels=['Negative', 'Positive'])
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.title('Confusion Matrix Heatmap')
plt.show()- Run the Streamlit app
streamlit run app.py- The app will be accessible at http://localhost:8501. Provide input text and get the sentiment behind the text
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch- Commit your changes:
git commit -m "Add feature"- Push to the branch:
git push origin feature-branch- Create a pull request.
This project is licensed under the MIT License - See the LICENSE file for details.