Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Implementing Text Classification in Python

vujennyfer
8 - Asteroid

Hello,

I am trying to use Python (or if you could recommend a better tool) to determine if a review is "negative" or "positive". I have tried the Naive Bayes classifier tool but it needs at least 2 fields to train the model. If there is a way to truly get the model to learn text classification (NLP), that would be very helpful! I've attached a training set labeling if a review is negative or positive, and a test set that would see if the model could determine if it was "negative" or "positive". 

 

Training set: 

vujennyfer_0-1624036710184.png

Test set (desired outcome is the review type being predicted):

vujennyfer_1-1624036765229.png

 

6 REPLIES 6
AkimasaKajitani
17 - Castor
17 - Castor

Hi @vujennyfer 

 

I made the workflow for you.

 

Python code is as follows.

 

from sklearn.naive_bayes import MultinomialNB
from sklearn.feature_extraction.text import CountVectorizer

#Read from AlteryxData
df = Alteryx.read("#1")
dfp = Alteryx.read("#2")

#Make Model
clf = MultinomialNB()
vec = CountVectorizer(min_df=1)
X = vec.fit_transform(df['review'])
clf.fit(X, df['review_type'])

#Predict
X_p = vec.transform(dfp['review'])
predicted = clf.predict(X_p)

# Output the list of files as dataframe
dfp['review_type_predicted'] = predicted
Alteryx.write(dfp,1)

 

 Result:

AkimasaKajitani_0-1624074164980.png

 

mutama
Alteryx
Alteryx

Hi @vujennyfer ,

 

Have you tried exploring the Sentiment Analysis tool under the Alteryx Intelligence Suite kit? Here’s a nice guide on how to use the tool in a code-free manner: https://community.alteryx.com/t5/Data-Science/Try-Sentiment-Analysis-with-Designer-You-Must/ba-p/589...

 

The tool uses the open-source VADER package. Hope this helps! 

Best,

Michael

vujennyfer
8 - Asteroid

Thank you SO MUCH @AkimasaKajitani! This worked!! 🙂 

vujennyfer
8 - Asteroid

Hi @mutama, I've tried to download it but unfortunately it comes at an additional cost. 

JeffA
Alteryx Alumni (Retired)

@vujennyferGlad your issue was sorted out! I'm just here to let you know about a new tool called Jupyter Flow. It will allow you to create cool notebooks like the one @AkimasaKajitani helped you fix, but you'll also be able to share the workflow and run it on Alteryx Server. Enjoy solving!

Jeff Arnold
Sr. Full Stack Software Engineer | Alteryx
nbeaudoin
5 - Atom

It looks like the OP is asking about a supervised model, but Alteryx rep responded with an unsupervised model solution using Intelligence Suite. Does Intel Suite offer the ability to do supervised learning (ie, classification models with text inputs using TF-IDF)? 

Labels