Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 3
Supervised Learning Using Python
trainData = [[3,3,3,, 'A'], [5,5,5,, 'B']]
testData = [7,7,7]
k = 1
neighbors = getClosePoints(trainData, testData, 1)
print(neighbors)
Sentiment Analysis
Sentiment analysis is an interesting application of text classification. For
example, say one airline client wants to analyze its customer feedback.
It classifies the feedback according to sentiment (positive/negative) and
also by aspect (food/staff/punctuality). After that, it can easily understand
its strengths in business (the aspect that has the maximum positive
feedback) and its weaknesses (the aspect that has the maximum negative
feedback). The airline can also compare this result with its competitor.
One interesting advantage of doing a comparison with the competitor is
that it nullifies the impact of the accuracy of the model because the same
accuracy is applied to all competitors. This is simple to implement in
Python using the textblob library, as shown here:
from textblob.classifiers import NaiveBayesClassifier
train = [('I love this sandwich.', 'pos'), ('this is an
amazing place!', 'pos'),('I feel very good about these
beers.', 'pos'),('this is my best work.', 'pos'),("what
an awesome view", 'pos'),('I do not like this restaurant',
'neg'),('I am tired of this stuff.', 'neg'),("I can't deal with
this", 'neg'),('he is my sworn enemy!', 'neg'),('my boss is
horrible.', 'neg')]
65