Classify customer reviews or support tickets as positive, negative, or neutral to analyze the satisfaction of customers.
A sentiment model analyzes text data to determine expressed sentiment. It is trained on a labeled dataset of positive, negative, or neutral examples. These models are used in e.g. social media and customer feedback analysis. They can provide valuable insights into customer opinions and preferences, allowing businesses to improve their products.
Here is an example on how to build an ML model in Peliqan.io with a few lines of Python code.
Import required modules
import pandas as pd
import numpy as np
import string
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.feature_extraction.text import TfidfVectorizer
from joblib import dumpLoad a dataset
Load data from a table into a dataframe (df), e.g. support tickets on which we want to apply sentiment analysis.
# Load Data
dbconn = pq.dbconnect(pq.DW_NAME)
df = dbconn.fetch(pq.DW_NAME, 'schema_name', 'support_tickets', df = True)
df = df.drop('Prediction', axis=1)Using Streamlit to build an app
We use the Streamlit module (st), built into Peliqan.io, to build a UI and show data.
# Show a title (st = Streamlit module)
st.title("Sentiment Analysis")
# Show some text
st.text("Sample data")
# Show the dataframe
st.dataframe(df.head(), use_container_width=True)Data Pre-processing
Let’s start with cleaning the text by removing punctuations and repeating common words (these are called stop words in NLP) to make it ready for future use.
To learn more about data pre-processing in NLP visit this guide or here.
Model Training & Evaluation
To learn more about vectorizing sentences click here.
Next Steps
- Using Peliqan you can create an app for business users to consume the model you have created in a simple and intuitive UI. Learn more about creating apps for users to consume your model.
- You can make predictions on real-time incoming data using the saved model. Learn more about making real-time predictions on new incoming data.
- You can make real-time predictions on new incoming data and send alerts to Slack if the model makes a prediction above a certain threshold.