Sentiment Analysis Essentials

21/03/2026

Understand how your customers truly feel with our comprehensive sentiment analysis solutions. We transform unstructured text from reviews, social media, support tickets, and surveys into clear, actionable insights. By combining rule-based methods with modern machine learning, we detect positive, negative, and neutral opinions, as well as key emotions and recurring themes. Use these insights to improve products, refine messaging, and respond faster to emerging issues. Whether you are a startup or an established enterprise, our sentiment analysis helps you make smarter, data-driven decisions and build stronger relationships with your audience.

๐Ÿ’ก What is Sentiment Analysis?

Sentiment Analysis is a technique in AI that helps computers understand how people feel about something from their text.

๐Ÿ‘‰ In simple words:
It answers the question โ€” "Is this positive, negative, or neutral?"

๐Ÿ“Œ Everyday Examples

1. Product Review

  • "This phone is amazing!" โ†’ โœ… Positive
  • "Battery life is terrible." โ†’ โŒ Negative
  • "It's okay, nothing special." โ†’ ๐Ÿ˜ Neutral

2. Social Media Post

  • "I love this movie!" โ†’ Positive
  • "Worst experience ever." โ†’ Negative
  • "Watched a movie today." โ†’ Neutral

๐Ÿง  How Does It Work (Very Simple View)?

Think of it like a smart keyword checker:

  • Words like love, great, amazing โ†’ Positive
  • Words like bad, worst, hate โ†’ Negative

๐Ÿ‘‰ AI models go beyond keywords and understand context + tone.

๐Ÿ› ๏ธ Where is it Used?

  1. Business
    • Understand customer feedback
    • Improve products
  2. Social Media Monitoring
    • Track public opinion
  3. Customer Support
    • Detect angry customers quickly
  4. Elections / Politics
    • Analyze public mood

๐ŸŽฏ Simple Real-Life Analogy

Imagine a teacher reading student feedback forms:

  • If most say "good teaching" โ†’ Positive
  • If many say "confusing" โ†’ Negative

๐Ÿ‘‰ The teacher is doing manual sentiment analysis!

โšก Types of Sentiment

  • Positive ๐Ÿ˜Š
  • Negative ๐Ÿ˜ก
  • Neutral ๐Ÿ˜
  • (Advanced) Mixed / Emotion-based (happy, angry, sad)

๐Ÿš€ One-Line Summary

๐Ÿ‘‰ Sentiment Analysis = Teaching computers to understand human feelings from text.

๐Ÿ˜Š 1. Food Delivery Experience

  • "Food was delicious and arrived on time!" โ†’ โœ… Positive
  • "Delivery was late and food was cold." โ†’ โŒ Negative
  • "Got my order." โ†’ ๐Ÿ˜ Neutral

๐Ÿ‘‰ Used by apps like Swiggy/Zomato to improve service. 

๐Ÿ“ฑ 2. Mobile Phone Review

  • "Camera quality is เคถเคพเคจเคฆเคพเคฐ!" โ†’ โœ… Positive
  • "Battery drains too fast." โ†’ โŒ Negative
  • "Phone is okay for daily use." โ†’ ๐Ÿ˜ Neutral

๐Ÿ‘‰ Companies analyze this to improve future phones. 

๐ŸŽฌ 3. Movie Feedback

  • "This movie is fantastic!" โ†’ โœ… Positive
  • "Waste of time." โ†’ โŒ Negative
  • "Average story." โ†’ ๐Ÿ˜ Neutral

๐Ÿ‘‰ Helps decide if a movie is a hit or flop.

๐Ÿ›’ 4. Online Shopping Reviews

  • "Product quality is excellent." โ†’ โœ… Positive
  • "Received damaged item." โ†’ โŒ Negative
  • "Product is as described." โ†’ ๐Ÿ˜ Neutral

๐Ÿ‘‰ Amazon/Flipkart use this heavily.

๐Ÿง‘โ€๐Ÿซ 5. Student Feedback

  • "Teacher explains very clearly." โ†’ โœ… Positive
  • "Too fast, difficult to understand." โ†’ โŒ Negative
  • "Class was okay." โ†’ ๐Ÿ˜ Neutral

๐Ÿ‘‰ Schools/colleges improve teaching quality.

๐Ÿš€ Final Simple Idea

๐Ÿ‘‰ Imagine a machine reading thousands of such sentences and quickly telling:

  • "Most people are happy"
  • "Customers are unhappy"

That's Sentiment Analysis in action.

If you want, I can next:

  • Give fun MCQs for students
  • Show how AI actually detects sentiment (step-by-step)
  • Or create a short viral YouTube script for this topic ๐ŸŽฌ

Show how AI actually detects sentiment (step-by-step)

Here's a clear, step-by-step view of how AI actually detects sentiment โ€” explained in the simplest possible way ๐Ÿ‘‡

๐Ÿง  Step 1: Input Text (What user says)

Example input:

"The phone camera is amazing but battery is bad."

๐Ÿ‘‰ This is raw human language.

โœ‚๏ธ Step 2: Text Cleaning (Make it simple)

AI cleans the sentence:

  • Removes unnecessary words (like "the", "is")
  • Converts to lowercase

๐Ÿ‘‰ Result:

"phone camera amazing battery bad"

๐Ÿ”ข Step 3: Convert Words โ†’ Numbers

Computers don't understand words, so:

  • "amazing" โ†’ +0.9
  • "bad" โ†’ -0.8

๐Ÿ‘‰ Sentence becomes numbers:

[0.9, -0.8]

โš–๏ธ Step 4: Sentiment Scoring

AI combines scores:

  • Positive: +0.9
  • Negative: -0.8

๐Ÿ‘‰ Final score โ‰ˆ slightly positive

๐Ÿท๏ธ Step 5: Final Classification

AI gives output:

  • โœ… Positive
  • โŒ Negative
  • ๐Ÿ˜ Neutral

๐Ÿ‘‰ In our case:

Mixed / Slightly Positive

๐Ÿค– What's Happening Behind the Scenes?

In real AI models:

  • Uses Machine Learning / Deep Learning
  • Trained on thousands of reviews
  • Understands context like:
    • "not good" โ†’ Negative
    • "not bad" โ†’ Positive

๐ŸŽฏ One-Line Flow

๐Ÿ‘‰ Text โ†’ Clean โ†’ Convert to Numbers โ†’ Score โ†’ Label

๐Ÿš€ Real-Life Analogy

Think of it like a teacher checking answers:

  • Reads sentence
  • Picks important words
  • Judges tone
  • Gives result

๐Ÿ‘‰ AI is doing the same โ€” but at super speed โšก


โš–๏ธ How Sentiment Scores Are Created (Simple Idea)

๐Ÿ‘‰ Each word has a score:

  • Positive words โ†’ + value
  • Negative words โ†’ โˆ’ value

AI adds them up to get final sentiment.

๐Ÿงพ Example 1: Simple Positive Sentence

Sentence:

"This product is amazing and useful"

Step-by-step scoring:

  • amazing โ†’ +0.9
  • useful โ†’ +0.7

๐Ÿ‘‰ Total Score = +1.6

โœ… Final Sentiment = Positive

โŒ Example 2: Clearly Negative

Sentence:

"This service is slow and terrible"

Scoring:

  • slow โ†’ -0.5
  • terrible โ†’ -0.9

๐Ÿ‘‰ Total Score = -1.4

โŒ Final Sentiment = Negative

โš–๏ธ Example 3: Mixed Sentiment

Sentence:

"Food is tasty but expensive"

Scoring:

  • tasty โ†’ +0.8
  • expensive โ†’ -0.6

๐Ÿ‘‰ Total Score = +0.2

๐Ÿ˜ Final Sentiment = Neutral / Slightly Positive

๐Ÿคฏ Example 4: Negation (Important!)

Sentence:

"The movie is not good"

Normal scoring:

  • good โ†’ +0.7

But "not" flips meaning ๐Ÿ‘‡
๐Ÿ‘‰ Adjusted score:

  • not good โ†’ -0.6

โŒ Final Sentiment = Negative

๐Ÿ”ฅ Example 5: Strong Emotion

Sentence:

"I absolutely love this!"

Scoring:

  • love โ†’ +1.0
  • absolutely โ†’ boosts intensity

๐Ÿ‘‰ Total Score โ‰ˆ +1.3

โœ… Final Sentiment = Very Positive

๐Ÿ˜ Example 6: Neutral Case

Sentence:

"The meeting was held at 3 PM"

Scoring:

  • No emotional words โ†’ 0

๐Ÿ‘‰ Total Score = 0

๐Ÿ˜ Final Sentiment = Neutral

๐Ÿง  How AI Decides Final Label

Score Range Sentiment
> +0.5 Positive
-0.5 to +0.5 Neutral
< -0.5 Negative

๐ŸŽฏ Final Insight

๐Ÿ‘‰ AI is basically doing:

"Emotional Math" ๐Ÿงฎ

  • Add positive words
  • Subtract negative words
  • Adjust for context

๐Ÿš€ Pro-Level Insight (Useful for You ๐Ÿ‘€)

In real systems (like BERT / ChatGPT-like models):

  • It's NOT just word scores
  • It understands:
    • Context
    • Sarcasm ("Great, another delay ๐Ÿ˜’")
    • Sentence structure

๐Ÿง  What is Natural Language Processing?

NLP is a branch of AI that helps computers:

  • Understand human language
  • Read, write, and interpret text or speech

๐Ÿ‘‰ Examples:

  • Chatbots (like ChatGPT)
  • Google Translate
  • Voice assistants

๐Ÿ’ก Where Sentiment Analysis Fits

๐Ÿ‘‰ Think of NLP as a big umbrella โ˜‚๏ธ

Inside it, there are many tasks:

  • Text classification
  • Translation
  • Named Entity Recognition
  • Sentiment Analysis (one of them)

๐ŸŽฏ What is Sentiment Analysis in NLP?

๐Ÿ‘‰ It is a sub-task of NLP that focuses on:

  • Detecting emotions in text
  • Classifying into:
    • Positive
    • Negative
    • Neutral

๐Ÿ“Œ Simple Analogy

  • NLP = Entire English Language Subject ๐Ÿ“š
  • Sentiment Analysis = One Chapter (Emotions in Text ๐Ÿ˜Š๐Ÿ˜ก)

๐Ÿš€ Real-Life Connection

When companies:

  • Analyze reviews
  • Track customer mood
  • Monitor social media

๐Ÿ‘‰ They are using:
NLP techniques โ†’ specifically Sentiment Analysis


๐Ÿš€ Major Applications of Sentiment Analysis

๐Ÿ›’ 1. Customer Feedback & Reviews (Most Common)

  • Product reviews
  • App ratings
  • Service feedback

๐Ÿ‘‰ Helps companies improve products.

๐Ÿ“ฑ 2. Social Media Monitoring

  • Analyze tweets, comments, posts
  • Track public opinion

๐Ÿ‘‰ Example:
"What people think about a new policy or movie"

๐Ÿ›๏ธ 3. Politics & Elections

  • Measure public mood toward leaders
  • Analyze speeches and debates

๐Ÿ‘‰ Used during elections to understand voters.

๐Ÿ’ฐ 4. Stock Market & Finance

  • Analyze financial news & tweets
  • Predict market trends

๐Ÿ‘‰ Example:
Positive news โ†’ stock may go up ๐Ÿ“ˆ

๐ŸŽง 5. Customer Support Automation

  • Detect angry customers
  • Prioritize urgent complaints

๐Ÿ‘‰ Improves response time.

๐ŸŽฌ 6. Entertainment Industry

  • Analyze movie/music reactions
  • Predict success of content

๐Ÿฅ 7. Healthcare & Mental Health

  • Detect stress, depression from text
  • Monitor patient feedback

๐Ÿ‘‰ Very important emerging use.

๐ŸŽ“ 8. Education

  • Analyze student feedback
  • Improve teaching methods

๐ŸŽฏ Final Insight

๐Ÿ‘‰ Customer reviews = just the starting point

Sentiment Analysis is actually about:

Understanding human emotions at scale across industries

๐Ÿฅ Sentiment Analysis in Healthcare

๐Ÿ’ก 1. Patient Feedback Analysis

  • Patients write reviews about hospitals/doctors
  • AI detects:
    • Positive โ†’ "Doctor was very caring"
    • Negative โ†’ "Waiting time was too long"

๐Ÿ‘‰ Hospitals improve services based on this.

๐Ÿง  2. Mental Health Monitoring

  • AI analyzes text from:
    • Chats
    • Social media posts
    • Journals

๐Ÿ‘‰ Example:

  • "I feel hopeless and tired" โ†’ โš ๏ธ Negative emotional signal

๐Ÿ‘‰ Helps detect:

  • Depression
  • Anxiety
  • Stress

๐Ÿค– 3. AI Chatbots in Healthcare

  • Chatbots talk to patients
  • Detect emotions like:
    • Fear
    • Pain
    • Anger

๐Ÿ‘‰ Then respond more carefully:

  • Calm tone
  • Urgent escalation if needed

๐Ÿ“Š 4. Drug & Treatment Feedback

  • Analyze patient comments about medicines

๐Ÿ‘‰ Example:

  • "This medicine works great" โ†’ Positive
  • "Side effects are terrible" โ†’ Negative

๐Ÿ‘‰ Helps pharma companies improve drugs.

๐ŸŽ“ Sentiment Analysis in Education

4

๐Ÿง‘โ€๐Ÿซ 1. Student Feedback Analysis

  • Students give feedback on:
    • Teachers
    • Courses

๐Ÿ‘‰ Example:

  • "Concepts explained clearly" โ†’ Positive
  • "Too fast, confusing" โ†’ Negative

๐Ÿ‘‰ Institutions improve teaching quality.

๐Ÿ’ป 2. Online Learning Platforms (EdTech)

  • Platforms analyze:
    • Comments
    • Discussion forums

๐Ÿ‘‰ Detect:

  • Confusion
  • Satisfaction
  • Frustration

๐Ÿ‘‰ Example:

  • "This topic is hard" โ†’ Need better explanation

๐Ÿ“‰ 3. Dropout Prediction

  • If many students show negative sentiment:
    • "I don't understand anything"
    • "Course is too tough"

๐Ÿ‘‰ AI flags students at risk of dropping out

๐ŸŽฏ 4. Personalized Learning

  • AI adjusts content based on student emotion

๐Ÿ‘‰ Example:

  • Frustrated โ†’ simpler explanation
  • Interested โ†’ advanced content

๐Ÿ”ฅ Final Insight

๐Ÿ‘‰ In both fields, sentiment analysis helps to:

  • Understand human emotions at scale
  • Take early action (very important in healthcare)
  • Improve experience and outcomes

๐Ÿš€ One-Line Summary 

๐Ÿ‘‰ "In healthcare, sentiment analysis is used for patient feedback, mental health monitoring, and chatbots; in education, it helps analyze student feedback, improve learning, and predict dropouts."

๐Ÿฅ Mini Project: Healthcare Sentiment Analysis (Python)

๐ŸŽฏ Objective

Build a model that classifies patient feedback into:

  • โœ… Positive
  • โŒ Negative
  • ๐Ÿ˜ Neutral

๐Ÿงพ Step 1: Sample Dataset (You can start small)

data = [
("Doctor was very kind and helpful", "positive"),
("Waiting time was too long", "negative"),
("Treatment was okay", "neutral"),
("Staff was rude and unprofessional", "negative"),
("Excellent care and support", "positive"),
("The experience was average", "neutral")
]

โš™๏ธ Step 2: Install Required Libraries

pip install scikit-learn pandas

๐Ÿง  Step 3: Build the Model (Simple & Powerful)

import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
# Convert data to DataFrame
df = pd.DataFrame(data, columns=["text", "label"])
# Convert text to numbers
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(df["text"])
# Labels
y = df["label"]
# Train model
model = MultinomialNB()
model.fit(X, y)
print("Model trained successfully!")

๐Ÿ” Step 4: Test the Model

test_sentences = [
"Doctor was amazing",
"Very bad service",
"It was fine"
]
X_test = vectorizer.transform(test_sentences)
predictions = model.predict(X_test)
for text, pred in zip(test_sentences, predictions):
print(f"{text} --> {pred}")

๐Ÿ“Š Expected Output

Doctor was amazing --> positive
Very bad service --> negative
It was fine --> neutral

๐Ÿš€ Step 5: Improve the Model (Advanced Touch)

Add this for better accuracy:

from sklearn.pipeline import Pipeline
model_pipeline = Pipeline([
('vectorizer', CountVectorizer()),
('classifier', MultinomialNB())
])
model_pipeline.fit(df["text"], df["label"])

๐Ÿ’ก Real-World Upgrade Ideas (Very Valuable ๐Ÿ”ฅ)

You can extend this project into a portfolio-level project:

โœ… 1. Use Real Dataset

  • Kaggle healthcare reviews dataset

โœ… 2. Add Sentiment Score

  • Use TextBlob or VADER

โœ… 3. Build Web App

  • Use Streamlit

pip install streamlit

๐ŸŒ Bonus: Simple Streamlit App

import streamlit as st
st.title("Healthcare Sentiment Analyzer")
user_input = st.text_area("Enter patient feedback:")
if st.button("Analyze"):
result = model_pipeline.predict([user_input])
st.write("Sentiment:", result[0])

Run:

streamlit run app.py

๐Ÿ”ฅ Pro Tip (For You Specifically)

Given your background in AI + Cybersecurity + Teaching, you can position it as:

๐Ÿ‘‰ "AI-driven patient experience monitoring system for hospitals"

๐Ÿง  MCQs: Healthcare Sentiment Analysis (Mini Project)

Q1. What is the main goal of the healthcare sentiment model?

A. Predict diseases
B. Classify patient feedback
C. Store medical records
D. Diagnose patients

๐Ÿ‘‰ Answer: B
Explanation: The model classifies feedback into positive, negative, or neutral.

Q2. Which type of AI field is used in this project?

A. Computer Vision
B. Robotics
C. NLP
D. Networking

๐Ÿ‘‰ Answer: C
Explanation: Sentiment analysis is a part of Natural Language Processing.

Q3. What are the possible outputs of the model?

A. High, Medium, Low
B. Positive, Negative, Neutral
C. True, False
D. 0, 1

๐Ÿ‘‰ Answer: B

โš™๏ธ Python & Implementation

Q4. Which library is used for machine learning in the project?

A. NumPy
B. Pandas
C. Scikit-learn
D. Matplotlib

๐Ÿ‘‰ Answer: C

Q5. What does CountVectorizer do?

A. Counts patients
B. Converts text into numbers
C. Stores data
D. Cleans images

๐Ÿ‘‰ Answer: B
Explanation: ML models need numbers, not text.

Q6. Which algorithm is used in the project?

A. Linear Regression
B. K-Means
C. Naive Bayes
D. Decision Tree

๐Ÿ‘‰ Answer: C

Q7. What is the purpose of .fit() method?

A. Test the model
B. Train the model
C. Display output
D. Clean data

๐Ÿ‘‰ Answer: B

Q8. What does .predict() do?

A. Train data
B. Convert text
C. Predict sentiment
D. Remove errors

๐Ÿ‘‰ Answer: C

๐Ÿ” Conceptual Understanding

Q9. Why do we convert text into numbers?

A. To reduce size
B. Computers understand only numbers
C. To delete words
D. To speed typing

๐Ÿ‘‰ Answer: B

Q10. What is the role of labels in the dataset?

A. Store text
B. Represent sentiment category
C. Remove duplicates
D. Format data

๐Ÿ‘‰ Answer: B

Q11. Which sentence is likely to be classified as positive?

A. "Very long waiting time"
B. "Doctor was very caring"
C. "Staff was rude"
D. "Not satisfied"

๐Ÿ‘‰ Answer: B

๐Ÿš€ Advanced / Application-Based

Q12. Which tool is used to build a simple web app in this project?

A. Flask
B. Django
C. Streamlit
D. TensorFlow

๐Ÿ‘‰ Answer: C

Q13. What is the benefit of using a pipeline in Scikit-learn?

A. Stores data
B. Combines steps like vectorization and model
C. Deletes errors
D. Improves UI

๐Ÿ‘‰ Answer: B

Q14. Which of the following is a real healthcare use case?

A. Image editing
B. Patient feedback analysis
C. Game development
D. File compression

๐Ÿ‘‰ Answer: B

Q15. If a model predicts many wrong sentiments, what should you improve?

A. Keyboard
B. Dataset quality
C. Screen resolution
D. Internet speed

๐Ÿ‘‰ Answer: B

๐ŸŽฏ Bonus: Scenario-Based MCQ

Q16. A patient writes:

"The doctor was good but the staff was rude."

What will likely be the sentiment?

A. Positive
B. Negative
C. Neutral / Mixed
D. Cannot determine

๐Ÿ‘‰ Answer: C
Explanation: Mixed sentiment (both positive and negative words).

๐Ÿฅ Healthcare Sentiment Analysis (Full Python Code)

# Install required libraries (run once if needed)
# pip install scikit-learn pandas
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import Pipeline
# -----------------------------
# Step 1: Create Dataset
# -----------------------------
data = [
("Doctor was very kind and helpful", "positive"),
("Waiting time was too long", "negative"),
("Treatment was okay", "neutral"),
("Staff was rude and unprofessional", "negative"),
("Excellent care and support", "positive"),
("The experience was average", "neutral"),
("Nurses were very caring", "positive"),
("Bad hygiene in hospital", "negative")
]
df = pd.DataFrame(data, columns=["text", "label"])
# -----------------------------
# Step 2: Build Model Pipeline
# -----------------------------
model = Pipeline([
('vectorizer', CountVectorizer()),
('classifier', MultinomialNB())
])
# Train the model
model.fit(df["text"], df["label"])
print("โœ… Model trained successfully!\n")
# -----------------------------
# Step 3: Test with Sample Data
# -----------------------------
test_sentences = [
"Doctor was amazing",
"Very bad service",
"It was fine",
"Staff was very helpful",
"Worst hospital experience"
]
predictions = model.predict(test_sentences)
print("๐Ÿ” Test Results:")
for text, pred in zip(test_sentences, predictions):
print(f"{text} --> {pred}")
# -----------------------------
# Step 4: User Input (Interactive)
# -----------------------------
print("\n๐Ÿ’ฌ Enter your own feedback (type 'exit' to stop):")
while True:
user_input = input("Enter feedback: ")if user_input.lower() == 'exit':
print("๐Ÿ‘‹ Exiting...")
breakresult = model.predict([user_input])[0]
print(f"๐Ÿ‘‰ Sentiment: {result}\n")

๐Ÿš€ What This Program Does

  • Trains a sentiment model on healthcare feedback
  • Predicts sentiment for:
    • Predefined test sentences
    • Your own input (live typing)

โ–ถ๏ธ How to Run

Option 1: Google Colab

  • Paste code โ†’ Run โ†’ Start typing feedback

Option 2: VS Code / Terminal

python sentiment.py

๐Ÿ’ก Sample Input/Output

Enter feedback: Doctor was very good
๐Ÿ‘‰ Sentiment: positive
Enter feedback: Service was horrible
๐Ÿ‘‰ Sentiment: negative

๐Ÿ”ฅ Upgrade Ideas (Next Step)

  • Add TextBlob for sentiment score
  • Replace with TF-IDF Vectorizer
  • Use BERT model (advanced AI)
  • Build Streamlit web app

If you want, I can next:

  • Convert this into a GUI app
  • Add accuracy evaluation (precision/recall)
  • Or make it YouTube tutorial script ๐ŸŽฌ

Good catch ๐Ÿ‘ โ€” your model is behaving incorrectly, and this is actually a very important learning moment.

โ— Why Your Model is Giving Wrong Results

๐Ÿ”ด Problem 1: Very Small Dataset

You trained on only ~8 sentences.

๐Ÿ‘‰ The model has never seen words like:

  • "great"
  • "good"

So it guesses randomly or incorrectly.

๐Ÿ”ด Problem 2: CountVectorizer Limitation

  • It only counts words
  • It does NOT understand meaning

So:

  • "good" โ‰  "excellent" (for the model)

๐Ÿ”ด Problem 3: No Training Examples for Common Words

Your dataset has:

  • "excellent" โœ…
  • but NOT "good" โŒ

๐Ÿ‘‰ So model doesn't know "good = positive"

โœ… Fix 1: Improve Dataset (MOST IMPORTANT)

Replace your dataset with this ๐Ÿ‘‡

data = [
("Doctor was very kind and helpful", "positive"),
("Excellent care and support", "positive"),
("Nurses were very caring", "positive"),
("Great service and good staff", "positive"),
("Doctor was amazing", "positive"),
("Very good treatment", "positive"),
("The service was good", "positive"),
("Waiting time was too long", "negative"),
("Staff was rude and unprofessional", "negative"),
("Bad hygiene in hospital", "negative"),
("Very bad service", "negative"),
("Worst hospital experience", "negative"),
("Treatment was terrible", "negative"),
("Treatment was okay", "neutral"),
("The experience was average", "neutral"),
("It was fine", "neutral")
]

โœ… Fix 2: Use TF-IDF (Better than CountVectorizer)

Replace this line:

from sklearn.feature_extraction.text import CountVectorizer

๐Ÿ‘‰ with:

from sklearn.feature_extraction.text import TfidfVectorizer

And update pipeline:

model = Pipeline([
('vectorizer', TfidfVectorizer()),
('classifier', MultinomialNB())
])

โœ… Fix 3: Add Lowercase + Stop Words Handling

TfidfVectorizer(lowercase=True, stop_words='english')

๐Ÿ”ฅ Final Improved Pipeline

model = Pipeline([
('vectorizer', TfidfVectorizer(lowercase=True, stop_words='english')),
('classifier', MultinomialNB())
])

๐ŸŽฏ What Will Improve Now

Input Before After
good โŒ negative โœ… positive
great โŒ negative โœ… positive
very bad maybe wrong โœ… negative

๐Ÿง  Key Learning (VERY IMPORTANT)

๐Ÿ‘‰ AI is not intelligent by default
It learns only from:

  • Data you give
  • Patterns it sees

๐Ÿ‘‰ Garbage in โ†’ Garbage out


โ— Why "poor" is still predicted as positive

๐Ÿ‘‰ Your model still hasn't learned that "poor" is negative

Even with TF-IDF, the model only learns from:

  • Words present in training data

๐Ÿ‘‰ If "poor" is missing or rare โ†’ model guesses based on other patterns.

โœ… Fix (Very Important)

๐Ÿ”ง Add More Negative Words to Dataset

Update your dataset like this ๐Ÿ‘‡

data = [
# Positive
("Doctor was very kind and helpful", "positive"),
("Excellent care and support", "positive"),
("Nurses were very caring", "positive"),
("Great service and good staff", "positive"),
("Doctor was amazing", "positive"),
("Very good treatment", "positive"),
("The service was good", "positive"),
# Negative (ADD MORE VARIETY HERE ๐Ÿ”ฅ)
("Waiting time was too long", "negative"),
("Staff was rude and unprofessional", "negative"),
("Bad hygiene in hospital", "negative"),
("Very bad service", "negative"),
("Worst hospital experience", "negative"),
("Treatment was terrible", "negative"),
("Poor service", "negative"),
("The doctor was poor in communication", "negative"),
("Very poor experience", "negative"),
# Neutral
("Treatment was okay", "neutral"),
("The experience was average", "neutral"),
("It was fine", "neutral")
]

๐Ÿ”ฅ Best Quick Fix (Recommended for You)

๐Ÿ‘‰ Use Prebuilt Sentiment Model (VADER)

This will instantly fix words like:

  • good
  • great
  • poor
  • excellent

๐Ÿ’ป Replace Prediction Code with This

# pip install nltk
from nltk.sentiment import SentimentIntensityAnalyzer
import nltk
nltk.download('vader_lexicon')
sia = SentimentIntensityAnalyzer()
while True:
text = input("Enter feedback: ")if text.lower() == 'exit':
breakscore = sia.polarity_scores(text)['compound']if score > 0.05:
sentiment = "positive"
elif score < -0.05:
sentiment = "negative"
else:
sentiment = "neutral"print(f"๐Ÿ‘‰ Sentiment: {sentiment}")

๐ŸŽฏ Why This Works Better

๐Ÿ‘‰ VADER already knows:

  • "good" โ†’ positive
  • "poor" โ†’ negative
  • "not good" โ†’ negative

๐Ÿ‘‰ No need to train from scratch

Share