This uses a previous python3 script inside R with reticulate to communicate python code within R. This will classify a wellness or health category based on it being one of either articles pulled from the internet on: physical therapy benefits, massage therapy benefits, chiropractic benefits, massage gun benefits, benefits of mental health services, cold stone therapy benefits, or cupping benefits. Then some ‘non professional’ google and twitter massage posts were added in to this selection to see how well the classifier could discriminate between one of the seven professional healthcare recommendations and a non-professional recommendation. This script also uses added data on medical professional or ER visit recommended based on user input. This data now has 9 categories to classify based on user input. Also, the risks, effects, and contraindications were scrubbed from the document of each class if it existed and placed into their corresponding feature of ‘contraindication’ or ‘risksAdverseEffect.’ This should improve the accuracy in classifying a recommendation for user inputs based on his or her requests.

The python packages were sklearn, matplotlib, pandas, numpy, nltk, textBlob, and regex. Some versions that work are later modules, for instance the re package was used that made regex obsolete because it is a build version that replaced regex for my version of python, 3.6.

library(reticulate)
## Warning: package 'reticulate' was built under R version 3.6.3
conda_list(conda = "auto") 
##           name                                                  python
## 1    Anaconda2                     C:\\Users\\m\\Anaconda2\\python.exe
## 2    djangoenv    C:\\Users\\m\\Anaconda2\\envs\\djangoenv\\python.exe
## 3     python36     C:\\Users\\m\\Anaconda2\\envs\\python36\\python.exe
## 4     python37     C:\\Users\\m\\Anaconda2\\envs\\python37\\python.exe
## 5 r-reticulate C:\\Users\\m\\Anaconda2\\envs\\r-reticulate\\python.exe

Without having my python IDE, Anaconda, open in the console I want to use the python36 environment, all the environments in Anaconda for python are listed above.

use_condaenv(condaenv = "python36")
import pandas as pd 
import matplotlib.pyplot as plt 
from textblob import TextBlob 
import sklearn 
import numpy as np 
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer 
from sklearn.naive_bayes import MultinomialNB 
from sklearn.metrics import classification_report, f1_score, accuracy_score, confusion_matrix 

import re
import string
import nltk 

np.random.seed(47) 
set.seed(47)

The following data table will not show in your Rstudio environment, but python inside your python IDE will store the table.

modalities = pd.read_csv('benefitsContraindications3.csv', encoding = 'unicode_escape') 
print(modalities.head())
##                                             Document  ...                                risksAdverseEffects
## 0  Chiropractic adjustments and treatments serve ...  ...                                                NaN
## 1  \r\nUnitedHealthcare Combats Opioid Crisis wit...  ...                                                NaN
## 2   The Safety of Chiropractic Adjustments\r\nBy ...  ...  Risks and side effects associated with chiropr...
## 3  Advanced Chiropractic Relief: 8 Key Benefits o...  ...                                                NaN
## 4  Heading to the spa can be a pampering treat, b...  ...                                                NaN
## 
## [5 rows x 6 columns]
print(modalities.tail())
##                                              Document  ... risksAdverseEffects
## 82  General guidelines - When to visit an emergenc...  ...                 NaN
## 83  \r\nHow to know where to go for sudden health ...  ...                 NaN
## 84  How to Know If You Need to Go to the E.R. With...  ...                 NaN
## 85  When to call 911 or go to an emergency room im...  ...                 NaN
## 86  Is It an Emergency?\r\n\r\nConditions we treat...  ...                 NaN
## 
## [5 rows x 6 columns]
print(modalities.shape)
## (87, 6)
print(modalities.columns)
## Index(['Document', 'Source', 'Topic', 'InternetSearch', 'Contraindications',
##        'risksAdverseEffects'],
##       dtype='object')
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text
modalities.tail()
##                                              Document  ... risksAdverseEffects
## 82  General guidelines - When to visit an emergenc...  ...                 NaN
## 83  \r\nHow to know where to go for sudden health ...  ...                 NaN
## 84  How to Know If You Need to Go to the E.R. With...  ...                 NaN
## 85  When to call 911 or go to an emergency room im...  ...                 NaN
## 86  Is It an Emergency?\r\n\r\nConditions we treat...  ...                 NaN
## 
## [5 rows x 6 columns]

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ... risksAdverseEffects
## 66  Do you prefer Pastel Pink vibes or All Black v...  ...                 NaN
## 40  \r\nWhat Is Cupping Therapy?And Should You Try...  ...                 NaN
## 14  What Are the Health Benefits of Massage?\r\n\r...  ...                 NaN
## 46  ll You Need To Know About Massage Gun\r\n31 Au...  ...                 NaN
## 47  \r\nBenefits of Vibration and Percussion Thera...  ...                 NaN
## 
## [5 rows x 6 columns]
print(modalities.tail())
##                                              Document  ... risksAdverseEffects
## 72        I adore men who massage me all over my body  ...                 NaN
## 8   BENEFITS OF MASSAGE\r\n\r\nYou know that post-...  ...                 NaN
## 71  Hey twitter I'm looking for a lady to massage ...  ...                 NaN
## 6   25 Reasons to Get a Massage\r\n\r\nNovember 5,...  ...                 NaN
## 7   7 Benefits of Massage Therapy\r\n\r\nMassage t...  ...                 NaN
## 
## [5 rows x 6 columns]
modalities.columns
## Index(['Document', 'Source', 'Topic', 'InternetSearch', 'Contraindications',
##        'risksAdverseEffects'],
##       dtype='object')
modalities.groupby('Topic').describe()
##                                 Document  ... risksAdverseEffects
##                                    count  ...                freq
## Topic                                     ...                    
## ER                                     6  ...                 NaN
## Not Professional                      16  ...                 NaN
## chiropractic benefits                  8  ...                   1
## cold stone benefits                   10  ...                 NaN
## cupping benefits                      10  ...                   1
## massage benefits                      12  ...                 NaN
## massage gun benefits                  10  ...                 NaN
## mental health services benefits        6  ...                 NaN
## physical therapy benefits              9  ...                 NaN
## 
## [9 rows x 20 columns]
modalities['length'] = modalities['Document'].map(lambda text: len(text))
print(modalities.head())
##                                              Document  ... length
## 66  Do you prefer Pastel Pink vibes or All Black v...  ...    133
## 40  \r\nWhat Is Cupping Therapy?And Should You Try...  ...   5471
## 14  What Are the Health Benefits of Massage?\r\n\r...  ...   1820
## 46  ll You Need To Know About Massage Gun\r\n31 Au...  ...   5521
## 47  \r\nBenefits of Vibration and Percussion Thera...  ...   3362
## 
## [5 rows x 7 columns]
modalities.length.plot(bins=20, kind='hist')
plt.show()

modalities.length.describe()
## count       87.000000
## mean      3842.275862
## std       3103.734864
## min         27.000000
## 25%       1366.500000
## 50%       3191.000000
## 75%       5936.500000
## max      12846.000000
## Name: length, dtype: float64
print(list(modalities.Document[modalities.length > 3800].index))
## [40, 46, 44, 49, 30, 17, 5, 25, 83, 58, 29, 1, 38, 54, 16, 2, 28, 26, 3, 42, 21, 27, 22, 9, 35, 34, 53, 41, 50, 55, 45, 84, 59, 23, 51, 7]
print(list(modalities.Topic[modalities.length > 3800]))
## ['cupping benefits', 'massage gun benefits', 'cupping benefits', 'massage gun benefits', 'mental health services benefits', 'physical therapy benefits', 'massage benefits', 'mental health services benefits', 'ER', 'cold stone benefits', 'mental health services benefits', 'chiropractic benefits', 'cupping benefits', 'massage gun benefits', 'physical therapy benefits', 'chiropractic benefits', 'mental health services benefits', 'mental health services benefits', 'chiropractic benefits', 'cupping benefits', 'physical therapy benefits', 'mental health services benefits', 'physical therapy benefits', 'massage benefits', 'cupping benefits', 'chiropractic benefits', 'massage gun benefits', 'cupping benefits', 'massage gun benefits', 'cold stone benefits', 'massage gun benefits', 'ER', 'cold stone benefits', 'physical therapy benefits', 'massage gun benefits', 'massage benefits']
modalities.hist(column='length', by='Topic', bins=5)


plt.show()

def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 66    [Do, you, prefer, Pastel, Pink, vibes, or, All...
## 40    [What, Is, Cupping, Therapy, And, Should, You,...
## 14    [What, Are, the, Health, Benefits, of, Massage...
## 46    [ll, You, Need, To, Know, About, Massage, Gun,...
## 47    [Benefits, of, Vibration, and, Percussion, The...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 66    [prefer, pastel, pink, vibe, black, vibe, lil,...
## 40    [cupping, therapy, try, 're, definitely, going...
## 14    [health, benefit, massage, many, type, massage...
## 46    [need, know, massage, gun, 31, august, 2019, 3...
## 47    [benefit, vibration, percussion, therapy, vibr...
## Name: Document, dtype: object
bow_transformer = CountVectorizer(analyzer=split_into_lemmas).fit(modalities['Document'])
print(len(bow_transformer.vocabulary_))
## 5102
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformer.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 75)    2
##   (0, 78)    1
##   (0, 94)    1
##   (0, 184)   2
##   (0, 209)   1
##   (0, 242)   1
##   (0, 245)   3
##   (0, 247)   1
##   (0, 248)   1
##   (0, 251)   2
##   (0, 290)   2
##   (0, 298)   1
##   (0, 319)   1
##   (0, 354)   1
##   (0, 355)   4
##   (0, 361)   1
##   (0, 384)   1
##   (0, 400)   1
##   (0, 417)   1
##   (0, 423)   1
##   (0, 437)   2
##   (0, 451)   7
##   :  :
##   (0, 4721)  1
##   (0, 4735)  2
##   (0, 4740)  1
##   (0, 4744)  1
##   (0, 4824)  3
##   (0, 4827)  1
##   (0, 4828)  2
##   (0, 4847)  1
##   (0, 4914)  2
##   (0, 4935)  4
##   (0, 4949)  2
##   (0, 4955)  1
##   (0, 4958)  2
##   (0, 4962)  1
##   (0, 4963)  1
##   (0, 4985)  1
##   (0, 5013)  2
##   (0, 5014)  1
##   (0, 5016)  1
##   (0, 5028)  2
##   (0, 5029)  1
##   (0, 5038)  1
##   (0, 5047)  1
##   (0, 5058)  1
##   (0, 5070)  1
modalities_bow = bow_transformer.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (87, 5102)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 17813
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 4.01%
modalities_bow
## <87x5102 sparse matrix of type '<class 'numpy.int64'>'
##  with 17813 stored elements in Compressed Sparse Row format>

Indexing is different in python compared to R. Python includes zero and when indicating a slice, the last value is ignored, so only up to the value. So it is used to slice, so that the next can start and include that number up to the empty slice which indicates the last value.


# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:69]
modalities_bow_test = modalities_bow[69:]
modalities_sentiment_train = modalities['Topic'][:69]
modalities_sentiment_test = modalities['Topic'][69:]

print(modalities_bow_train.shape)
## (69, 5102)
print(modalities_bow_test.shape)
## (18, 5102)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)
#print(predictions)


prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                   predictions                      Topic
## 82                         ER                         ER
## 41           cupping benefits           cupping benefits
## 52       massage gun benefits       massage gun benefits
## 65           massage benefits           Not Professional
## 50       massage gun benefits       massage gun benefits
## 55           massage benefits        cold stone benefits
## 45       massage gun benefits       massage gun benefits
## 84                         ER                         ER
## 86                         ER                         ER
## 59        cold stone benefits        cold stone benefits
## 23  physical therapy benefits  physical therapy benefits
## 80       massage gun benefits           Not Professional
## 51       massage gun benefits       massage gun benefits
## 72       massage gun benefits           Not Professional
## 8            massage benefits           massage benefits
## 71           massage benefits           Not Professional
## 6            massage benefits           massage benefits
## 7            massage benefits           massage benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.7222222222222222
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[3 0 0 0 0 0 0]
##  [0 0 0 0 2 2 0]
##  [0 0 1 0 1 0 0]
##  [0 0 0 1 0 0 0]
##  [0 0 0 0 3 0 0]
##  [0 0 0 0 0 4 0]
##  [0 0 0 0 0 0 1]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                            precision    recall  f1-score   support
## 
##                        ER       1.00      1.00      1.00         3
##          Not Professional       0.00      0.00      0.00         4
##       cold stone benefits       1.00      0.50      0.67         2
##          cupping benefits       1.00      1.00      1.00         1
##          massage benefits       0.50      1.00      0.67         3
##      massage gun benefits       0.67      1.00      0.80         4
## physical therapy benefits       1.00      1.00      1.00         1
## 
##                  accuracy                           0.72        18
##                 macro avg       0.74      0.79      0.73        18
##              weighted avg       0.62      0.72      0.64        18
## 
## 
## C:\Users\m\Anaconda2\envs\python36\lib\site-packages\sklearn\metrics\classification.py:1437: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples.
##   'precision', 'predicted', average, warn_for)

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['ER', 'Not Professional', 'chiropractic benefits',
##        'cold stone benefits', 'cupping benefits', 'massage benefits',
##        'massage gun benefits', 'mental health services benefits',
##        'physical therapy benefits'], dtype=object)

The ‘Not Professional’ class is not getting sorted alphabetically with the others nor is the ER class. This may be because of the uppercase priority in sorting that effects the order of probability readings.


def predict_modality(new_review): 
    new_sample = bow_transformer.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-ER\n 1-Non Professional\n 2-chiropractic therapy\n 3-cold stone therapy\n 4-cupping therapy\n 5-massage therapy\n 6-massage gun therapy\n 7-mental health therapy\n 8-physical therapy\n\n')
    
    if (pr[0][0] == max(pr[0])):
        print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][2]*100,'%')
        
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][3]*100,'%')
        
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][4]*100,'%')
   
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][5]*100,'%')
    
    elif (pr[0][6] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][6]*100,'%')
    
    elif (pr[0][7] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][7]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][8]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.   0.03 0.33 0.07 0.02 0.51 0.01 0.01 0.01]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  51.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.   0.   0.01 0.94 0.04 0.01 0.   0.   0.  ]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  94.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.   0.12 0.05 0.16 0.11 0.22 0.19 0.07 0.08]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  22.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.03 0.   0.2  0.02 0.04 0.37 0.13 0.   0.2 ]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  37.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.12 0.03 0.36 0.06 0.02 0.37 0.01 0.01 0.01]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  37.0 %
## -----------------------------------------

The above should be under contraindications for massage, but we didn’t move that far. Those are listings of contraindications for massage in mentioning the dizzy, nausious, and breathing ragged. But we didn’t add in any medical professional services categories to our data to classify. We should do that later.

predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.   0.   0.3  0.   0.04 0.56 0.01 0.   0.09]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  56.00000000000001 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.01 0.1  0.09 0.05 0.3  0.02 0.01 0.39 0.03]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is mental health therapy for this recommendation with  39.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.   0.   0.   0.   0.   0.99 0.01 0.   0.  ]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  99.0 %
## -----------------------------------------


from sklearn.feature_extraction.text import TfidfVectorizer

bow_transformerTFIDF = TfidfVectorizer(analyzer=split_into_lemmas).fit(modalities['Document'])
print(len(bow_transformerTFIDF.vocabulary_))
## 5102
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerTFIDF.transform([modality4])
print(bow4)
##   (0, 5070)  0.0343016955623061
##   (0, 5058)  0.02351775744233836
##   (0, 5047)  0.017109259657448753
##   (0, 5038)  0.0343016955623061
##   (0, 5029)  0.026424862252912722
##   (0, 5028)  0.03421851931489751
##   (0, 5016)  0.018160377636647154
##   (0, 5014)  0.02933196706348709
##   (0, 5013)  0.02333325109144081
##   (0, 4985)  0.0343016955623061
##   (0, 4963)  0.019392510065849074
##   (0, 4962)  0.03139459075173173
##   (0, 4958)  0.029771020055084946
##   (0, 4955)  0.0343016955623061
##   (0, 4949)  0.03709605788703871
##   (0, 4935)  0.05954204011016989
##   (0, 4914)  0.03421851931489751
##   (0, 4847)  0.03139459075173173
##   (0, 4828)  0.03878502013169815
##   (0, 4827)  0.013780280073305366
##   (0, 4824)  0.041340840219916096
##   (0, 4744)  0.0343016955623061
##   (0, 4740)  0.021455133754093716
##   (0, 4735)  0.03709605788703871
##   (0, 4721)  0.02436223856466808
##   :  :
##   (0, 451)   0.08852091625908796
##   (0, 437)   0.045524686673871696
##   (0, 423)   0.02436223856466808
##   (0, 417)   0.01679054929193511
##   (0, 400)   0.0343016955623061
##   (0, 384)   0.026424862252912722
##   (0, 361)   0.019392510065849074
##   (0, 355)   0.04113417730901512
##   (0, 354)   0.0343016955623061
##   (0, 319)   0.026424862252912722
##   (0, 298)   0.021455133754093716
##   (0, 290)   0.052849724505825445
##   (0, 251)   0.05866393412697418
##   (0, 248)   0.02933196706348709
##   (0, 247)   0.03139459075173173
##   (0, 245)   0.06623696446880327
##   (0, 242)   0.022762343336935848
##   (0, 209)   0.017442798989282242
##   (0, 184)   0.03791568698219916
##   (0, 94)    0.02933196706348709
##   (0, 78)    0.022762343336935848
##   (0, 75)    0.05063926459735123
##   (0, 7) 0.11976481760214126
##   (0, 5) 0.04291026750818743
##   (0, 3) 0.052849724505825445
modalities_bow = bow_transformerTFIDF.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (87, 5102)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 17813
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 4.01%
modalities_bow
## <87x5102 sparse matrix of type '<class 'numpy.float64'>'
##  with 17813 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:69]
modalities_bow_test = modalities_bow[69:]
modalities_sentiment_train = modalities['Topic'][:69]
modalities_sentiment_test = modalities['Topic'][69:]

print(modalities_bow_train.shape)
## (69, 5102)
print(modalities_bow_test.shape)
## (18, 5102)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)
# print(predictions)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']

prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                   predictions                      Topic
## 82           Not Professional                         ER
## 41           cupping benefits           cupping benefits
## 52           massage benefits       massage gun benefits
## 65           Not Professional           Not Professional
## 50       massage gun benefits       massage gun benefits
## 55           massage benefits        cold stone benefits
## 45           massage benefits       massage gun benefits
## 84           Not Professional                         ER
## 86           Not Professional                         ER
## 59        cold stone benefits        cold stone benefits
## 23  physical therapy benefits  physical therapy benefits
## 80           Not Professional           Not Professional
## 51       massage gun benefits       massage gun benefits
## 72           Not Professional           Not Professional
## 8            massage benefits           massage benefits
## 71           Not Professional           Not Professional
## 6            massage benefits           massage benefits
## 7            massage benefits           massage benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.6666666666666666
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[0 3 0 0 0 0 0]
##  [0 4 0 0 0 0 0]
##  [0 0 1 0 1 0 0]
##  [0 0 0 1 0 0 0]
##  [0 0 0 0 3 0 0]
##  [0 0 0 0 2 2 0]
##  [0 0 0 0 0 0 1]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                            precision    recall  f1-score   support
## 
##                        ER       0.00      0.00      0.00         3
##          Not Professional       0.57      1.00      0.73         4
##       cold stone benefits       1.00      0.50      0.67         2
##          cupping benefits       1.00      1.00      1.00         1
##          massage benefits       0.50      1.00      0.67         3
##      massage gun benefits       1.00      0.50      0.67         4
## physical therapy benefits       1.00      1.00      1.00         1
## 
##                  accuracy                           0.67        18
##                 macro avg       0.72      0.71      0.68        18
##              weighted avg       0.65      0.67      0.61        18
## 
## 
## C:\Users\m\Anaconda2\envs\python36\lib\site-packages\sklearn\metrics\classification.py:1437: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples.
##   'precision', 'predicted', average, warn_for)

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['ER', 'Not Professional', 'chiropractic benefits',
##        'cold stone benefits', 'cupping benefits', 'massage benefits',
##        'massage gun benefits', 'mental health services benefits',
##        'physical therapy benefits'], dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerTFIDF.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-ER\n 1-Non Professional\n 2-chiropractic therapy\n 3-cold stone therapy\n 4-cupping therapy\n 5-massage therapy\n 6-massage gun therapy\n 7-mental health therapy\n 8-physical therapy\n\n')
    
    if (pr[0][0] == max(pr[0])):
        print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][2]*100,'%')
        
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][3]*100,'%')
        
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][4]*100,'%')
   
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][5]*100,'%')
    
    elif (pr[0][6] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][6]*100,'%')
    
    elif (pr[0][7] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][7]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][8]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.04 0.16 0.13 0.12 0.12 0.16 0.08 0.08 0.11]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is Non-Professional services for this recommendation with  16.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.04 0.14 0.1  0.23 0.12 0.12 0.07 0.07 0.09]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  23.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.04 0.17 0.11 0.12 0.13 0.14 0.09 0.08 0.12]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is Non-Professional services for this recommendation with  17.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.04 0.16 0.12 0.11 0.13 0.14 0.09 0.08 0.13]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is Non-Professional services for this recommendation with  16.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.05 0.16 0.12 0.12 0.13 0.15 0.08 0.08 0.11]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is Non-Professional services for this recommendation with  16.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.04 0.14 0.14 0.1  0.12 0.15 0.08 0.07 0.15]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  15.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.04 0.18 0.11 0.11 0.14 0.12 0.08 0.09 0.11]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is Non-Professional services for this recommendation with  18.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.04 0.16 0.12 0.12 0.12 0.17 0.09 0.08 0.1 ]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  17.0 %
## -----------------------------------------

The TF-IDF vectorized dtm performed worse in recommending an accurate class for the testing set and the short user inputs. Lets try out the N-grams and see if it is better.


N-gram Vectorization

modalities = pd.read_csv('benefitsContraindications3.csv', encoding = 'unicode_escape') 
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ...                                risksAdverseEffects
## 37  \r\nCupping Therapy\r\nIn this Article\r\n\r\n...  ...                                                NaN
## 66  Do you prefer Pastel Pink vibes or All Black v...  ...                                                NaN
## 31  \r\n21 Benefits of Chiropractic Adjustments\r\...  ...                                                NaN
## 13  \r\nThai Massage\r\n\r\nDuring a Thai massage,...  ...                                                NaN
## 2    The Safety of Chiropractic Adjustments\r\nBy ...  ...  Risks and side effects associated with chiropr...
## 
## [5 rows x 6 columns]
print(modalities.tail())
##                                              Document  ... risksAdverseEffects
## 80  So I'm meeting with my CPA yesterday.  Great g...  ...                 NaN
## 30   Mental Health Counselor Training, Skills, and...  ...                 NaN
## 72        I adore men who massage me all over my body  ...                 NaN
## 41  \r\n    Benefit\r\n    Possible Side Effects\r...  ...                 NaN
## 77  WhenÂ’s the last time you gave your man a back ...  ...                 NaN
## 
## [5 rows x 6 columns]
def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 37    [Cupping, Therapy, In, this, Article, Types, W...
## 66    [Do, you, prefer, Pastel, Pink, vibes, or, All...
## 31    [21, Benefits, of, Chiropractic, Adjustments, ...
## 13    [Thai, Massage, During, a, Thai, massage, the,...
## 2     [The, Safety, of, Chiropractic, Adjustments, B...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 37    [cupping, therapy, article, type, research, sh...
## 66    [prefer, pastel, pink, vibe, black, vibe, lil,...
## 31    [21, benefit, chiropractic, adjustment, woman,...
## 13    [thai, massage, thai, massage, therapist, us, ...
## 2     [safety, chiropractic, adjustment, lana, barhu...
## Name: Document, dtype: object
bow_transformerNgrams = CountVectorizer(analyzer=split_into_lemmas,ngram_range=(2,2)).fit(modalities['Document'])
          
print(len(bow_transformerNgrams.vocabulary_))
## 5102
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerNgrams.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 75)    2
##   (0, 78)    1
##   (0, 94)    1
##   (0, 184)   2
##   (0, 209)   1
##   (0, 242)   1
##   (0, 245)   3
##   (0, 247)   1
##   (0, 248)   1
##   (0, 251)   2
##   (0, 290)   2
##   (0, 298)   1
##   (0, 319)   1
##   (0, 354)   1
##   (0, 355)   4
##   (0, 361)   1
##   (0, 384)   1
##   (0, 400)   1
##   (0, 417)   1
##   (0, 423)   1
##   (0, 437)   2
##   (0, 451)   7
##   :  :
##   (0, 4721)  1
##   (0, 4735)  2
##   (0, 4740)  1
##   (0, 4744)  1
##   (0, 4824)  3
##   (0, 4827)  1
##   (0, 4828)  2
##   (0, 4847)  1
##   (0, 4914)  2
##   (0, 4935)  4
##   (0, 4949)  2
##   (0, 4955)  1
##   (0, 4958)  2
##   (0, 4962)  1
##   (0, 4963)  1
##   (0, 4985)  1
##   (0, 5013)  2
##   (0, 5014)  1
##   (0, 5016)  1
##   (0, 5028)  2
##   (0, 5029)  1
##   (0, 5038)  1
##   (0, 5047)  1
##   (0, 5058)  1
##   (0, 5070)  1
modalities_bow = bow_transformerNgrams.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (87, 5102)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 17813
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 4.01%
modalities_bow
## <87x5102 sparse matrix of type '<class 'numpy.int64'>'
##  with 17813 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:69]
modalities_bow_test = modalities_bow[69:]
modalities_sentiment_train = modalities['Topic'][:69]
modalities_sentiment_test = modalities['Topic'][69:]

print(modalities_bow_train.shape)
## (69, 5102)
print(modalities_bow_test.shape)
## (18, 5102)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                         predictions                            Topic
## 19        physical therapy benefits        physical therapy benefits
## 22        physical therapy benefits        physical therapy benefits
## 58              cold stone benefits              cold stone benefits
## 53             massage gun benefits             massage gun benefits
## 79                 massage benefits                 Not Professional
## 8                  massage benefits                 massage benefits
## 60              cold stone benefits              cold stone benefits
## 84                               ER                               ER
## 7              massage gun benefits                 massage benefits
## 34            chiropractic benefits            chiropractic benefits
## 43                 cupping benefits                 cupping benefits
## 49             massage gun benefits             massage gun benefits
## 14                 massage benefits                 massage benefits
## 80                 massage benefits                 Not Professional
## 30  mental health services benefits  mental health services benefits
## 72                 massage benefits                 Not Professional
## 41                 cupping benefits                 cupping benefits
## 77                 massage benefits                 Not Professional
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.7222222222222222
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[1 0 0 0 0 0 0 0 0]
##  [0 0 0 0 0 4 0 0 0]
##  [0 0 1 0 0 0 0 0 0]
##  [0 0 0 2 0 0 0 0 0]
##  [0 0 0 0 2 0 0 0 0]
##  [0 0 0 0 0 2 1 0 0]
##  [0 0 0 0 0 0 2 0 0]
##  [0 0 0 0 0 0 0 1 0]
##  [0 0 0 0 0 0 0 0 2]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                                  precision    recall  f1-score   support
## 
##                              ER       1.00      1.00      1.00         1
##                Not Professional       0.00      0.00      0.00         4
##           chiropractic benefits       1.00      1.00      1.00         1
##             cold stone benefits       1.00      1.00      1.00         2
##                cupping benefits       1.00      1.00      1.00         2
##                massage benefits       0.33      0.67      0.44         3
##            massage gun benefits       0.67      1.00      0.80         2
## mental health services benefits       1.00      1.00      1.00         1
##       physical therapy benefits       1.00      1.00      1.00         2
## 
##                        accuracy                           0.72        18
##                       macro avg       0.78      0.85      0.80        18
##                    weighted avg       0.63      0.72      0.66        18
## 
## 
## C:\Users\m\Anaconda2\envs\python36\lib\site-packages\sklearn\metrics\classification.py:1437: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples.
##   'precision', 'predicted', average, warn_for)

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['ER', 'Not Professional', 'chiropractic benefits',
##        'cold stone benefits', 'cupping benefits', 'massage benefits',
##        'massage gun benefits', 'mental health services benefits',
##        'physical therapy benefits'], dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerNgrams.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-ER\n 1-Non Professional\n 2-chiropractic therapy\n 3-cold stone therapy\n 4-cupping therapy\n 5-massage therapy\n 6-massage gun therapy\n 7-mental health therapy\n 8-physical therapy\n\n')
    
    if (pr[0][0] == max(pr[0])):
        print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][2]*100,'%')
        
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][3]*100,'%')
        
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][4]*100,'%')
   
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][5]*100,'%')
    
    elif (pr[0][6] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][6]*100,'%')
    
    elif (pr[0][7] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][7]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][8]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.01 0.01 0.28 0.22 0.01 0.41 0.04 0.01 0.01]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  41.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.   0.   0.02 0.89 0.06 0.01 0.02 0.   0.  ]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  89.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.   0.02 0.04 0.08 0.06 0.15 0.6  0.02 0.04]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  60.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.15 0.01 0.11 0.03 0.03 0.56 0.07 0.01 0.05]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  56.00000000000001 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.24 0.03 0.29 0.27 0.01 0.13 0.01 0.01 0.01]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is chiropractic therapy for this recommendation with  28.999999999999996 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.   0.   0.19 0.01 0.02 0.64 0.12 0.   0.02]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  64.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.01 0.02 0.09 0.19 0.18 0.03 0.1  0.37 0.02]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is mental health therapy for this recommendation with  37.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0. 0. 0. 0. 0. 1. 0. 0. 0.]]
## 
## 
## The respective order:
##  0-ER
##  1-Non Professional
##  2-chiropractic therapy
##  3-cold stone therapy
##  4-cupping therapy
##  5-massage therapy
##  6-massage gun therapy
##  7-mental health therapy
##  8-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  100.0 %
## -----------------------------------------

I would say the TF-IDF predicted better than count on this data for the vectorization, but lets try the ngrams vectorization with bigrams or adjacent word pairs.

With the new scrubbed risks data and the new class added of ER services to this data, we can conclude there was no improvement on accuracy or class prediction. We did get to test out the TF-IDF and N-grams vectorization and found that TF-IDF did well on the testing set or decent but not so well at all on the short user inputs when making a prediction. And the N-grams scored very poorly on the testing set and equally as badly on the short user inputs. It is safe to conclude that these vectorizations, and this data scrubbed of contraindications and with an added ER services group did terrible. We could see if just keeping the data being only scrubbed contraindications and without the added ER does well and also if the data not scrubbed of risks but having an added ER services class does well. But, for whatever reason, possibly needing more observations of Non Professional services that are just as long as the other web pulled documents or having more observations would do better as that is usually the case.

For now lets look at the word clouds now, when the data is scrubbed of risks/negative side effects/contraindications, and with the ER services class. ***

library(tidytext)
library(tm)
library(dplyr)
library(ggplot2)
library(tidyr)
library(wordcloud)

Lets read in the csv file if you don’t have it stored as Reviews15_results.

modalities <- read.csv('benefitsContraindications3.csv',
                              sep=',', header=TRUE, na.strings=c('',' ','NA'))
colnames(modalities)
## [1] "Document"            "Source"              "Topic"              
## [4] "InternetSearch"      "Contraindications"   "risksAdverseEffects"

Lets just use the userReviewOnlyContent and the userRatingValue columns.

modalities1 <- modalities[,c(1,3)]
head(modalities1)
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Document
## 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Chiropractic adjustments and treatments serve the needs of millions of people around the world.\n\n \n\nAdjustments offer effective, non-invasive and cost-effective solutions to neck and back pain, as well as a myriad of other medical issues.\n\nHave you ever stopped to wonder how many of us suffer from neck and back stiffness or pain?\n\nApart from the obvious discomfort, simple daily tasks such as driving a car, crossing a busy street and picking things up from the floor can become all too challenging for individuals experiencing such pain.\n\nAs anyone who has experienced pain would know, having restricted movement can be debilitating and unfortunately, our busy world doesn?t allow for us to stop.\n\n \nSome of the benefits of long-term chiropractic care include:\n\n    Chiropractors can identify mechanical issues that cause spine-related pain and offer a series of adjustments that provide near immediate relief. Following appointments, patients often report feeling their symptoms noticeably better.\n    When a chiropractor performs an adjustment, they can help restore movement in joints that have ?locked up?. This becomes possible as treatment allows muscles surrounding joints to relax, thereby reducing joint stiffness.\n    Many factors affect health, including exercise patterns, nutrition, sleep, heredity and the environment in which we live. Rather than just treat symptoms of the disease, chiropractic care focuses on a holistic approach to naturally maintain health and resist disease.\n    Chiropractic adjustments help restore normal function and movement to the entire body. Many patients report an improvement in their ability to move with efficiency and strength.\n    Many patients find delight in the results chiropractic adjustments have on old and chronic injuries. Whether an injury is, in fact, new or old, chiropractic care can help reduce pain, restore mobility and provide quick pain relief to all joints in the body. Such care can help maintain better overall health and thus faster recovery time.\n\nHave you ever noticed that when you are in pain and unable to perform regular or favorite activities, it can put a strain on emotional and mental well-being?\n\nFor example, the increased stress from not being able to properly perform a paid job. This, in turn, can have a negative impact on physical health with increases in heart rate and blood pressure. The domino effect often continues with sleep becoming disturbed, with resulting lethargy and tiredness during the day. Does anyone really feel up to exercising in this state?\n\nChiropractic care is a natural method of healing the body?s communication system and never relies on the use of pharmaceutical drugs or invasive surgery.\n\nDoctors of Chiropractic work collaboratively with other healthcare professionals. Should your condition require the attention of another healthcare profession, that recommendation or referral will be made.\n\n 
## 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    \nUnitedHealthcare Combats Opioid Crisis with Non-Opioid Benefits\nPhysical therapy and chiropractic care can prevent or reduce expensive, invasive spinal procedures, such as imaging or surgery, to reduce opioid use and cut costs.\nUnitedHealthcare, opioid, physical therapy, healthcare spending\n\nSource: Thinkstock\nShare on Twitter\n\nBy Kelsey Waddill\n\nOctober 29, 2019 - UnitedHealthcare (UHC) is combatting the opioid epidemic and high healthcare costs with new physical therapy and chiropractic care benefits to prevent, delay, or in some cases substitute for invasive spinal procedures.\n\n?With millions of Americans experiencing low back pain currently or at some point during their lifetimes, we believe this benefit design will help make a meaningful difference by improving health outcomes while reducing costs,? said Anne Docimo, MD, UnitedHealthcare chief medical officer.\n\nLower back pain is in part responsible for sustaining the opioid epidemic and also increases healthcare costs.\nDig Deeper\n\n    How Major Payers Provide Substance Abuse Care for Opioid Misuse\n    Opioid Overdoses Fall by 2% from 2017 to 2018, CDC Reports\n    Physical Therapy, Chiropractic Back Care Cut Opioid Use, Costs\n\nAlthough opioid overdoses fell by two percent from 2017 to 2018 and a legal battles aim to hold pharmaceutical companies accountable, there is no end in sight for the opioid epidemic. Industry professionals are still grappling with the balance between cutting opioid prescriptions will working to reduce patient pain.\n\nCommon conditions such as low back pain bolster the epidemic?s presence, with clinicians still prescribing the opioids against best practice recommendations. According to a recent OptumLabs study, 9 percent of patients with newly diagnosed low back pain are prescribed opioids and lower back pain currently contributes 52 percent to the overall opioid prescription rate.\n\nIn addition to boosting opioids distribution, alternative, invasive lower back pain treatments can significantly impact healthcare spending.\n\nIt is not new information that physical therapy and chiropractic care are effective, lower cost alternatives to spinal imaging or surgery. However, payers are still in the process of adopting the method.\n\nTo counteract the high-cost, high-risk potential of using opioids to treat back pain, UHC created a benefit that does not rely on medication or technology but rather on physical therapy and chiropractic care.\n\nThe benefit allows eligible employers to offer physical therapist and chiropractor visits with no out-of-pocket costs. Members who already receive physical therapist and chiropractic care benefits under UHC?s employer-sponsored health plans and who have maxed out their visits will not receive additional visits under this benefit.\n\nHowever, for those who still have visits to use and who choose physical therapy or chiropractic care over other forms of treatment, the copay or deductible for those visits will be waived and they will receive three visits at no cost.\n\nUHC has high expectations for the fiscal and physical impacts of this benefit.\n\nAccording to UHC?s analysis, the health payer expects that by 2021, opioid use will decrease by 19 percent. Spinal imaging test frequency and spinal surgeries will be reduced by 22 percent and 21 percent, respectively. In addition to these specific goals, UHC hopes to see a decrease in the overall cost of spinal care.\n\nThe same OptumLabs study demonstrated that UHC?s expectations are not without precedent.\n\nThe study looked at the correlation between out-of-pocket costs and patient utilization of noninvasive treatments. Researchers discovered that members whose copay was over $30 were a little under 30 percent less likely to choose physical therapy as opposed to more invasive treatments.\n\nAn American Journal of Managed Care study in June 2019 found that patients with high deductibles, typically over $1,000, were less likely to visit physical therapy.\n\nEligible employers may be brand new or renewing their membership. They must be fully insured and over 51 or more employees strong. The benefit is currently available in Connecticut, Florida, Georgia, New York, and North Carolina.\n\nHowever, UHC plans to expand the benefit from 2020 into 2021. By the end of this expansion period, the benefit will also be available to self-funded employers and organizations with an employee population between 2 and 50. The benefit will span ten states, primarily in the southeast.\n\n?This new benefit design may help encourage people with low back pain to get the right care at the right time and in the right setting, helping expand access to evidence-based and more affordable treatments,? said Docimo.
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     The Safety of Chiropractic Adjustments\nBy Lana Barhum\nMedically reviewed by Richard N. Fogoros, MD\nUpdated on January 31, 2020\nOrthopedics\nMore in Orthopedics\n\n    Home Office Ergonomics\n    Sprains & Strains\n    Fractures & Broken Bones\n    Physical Therapy\n    Orthopedic Surgery\n    Osteoporosis\n    Pediatric Orthopedics\n    Sports Injuries\n\nView All\nIn This Article\n\n    Chiropractic Adjustment\n    What Research Shows\n    Safety\n\nChiropractic adjustment, also called spinal manipulation, is a procedure done by a chiropractor using the hands or small instruments to apply controlled force to a spinal joint. The goal is to improve spinal motion and physical function of the entire body. Chiropractic adjustment is safe when performed by someone who is properly trained and licensed to practice chiropractic care. Complications are rare, but they are possible. Learn more about both the benefits and risks.\nChiropractic adjustment\nVerywell / Brianna Gilmartin \nChiropractic Adjustment\n\nOne of the most important reasons people seek chiropractic care is because it is a completely drug-free therapy. Someone dealing with joint pain, back pain, or headaches might consider visiting a chiropractor.\n\nThe goal of chiropractic adjustment is to place the body into a proper position so the body can heal itself. Treatments are believed to reduce stress on the immune system, reducing the potential for disease. Chiropractic care aims to address the entire body, including a person?s ability to move, perform, and even think.\nWhat Research Shows\n\nMany people wonder how helpful chiropractic care is in treating years of trauma and poor posture. There have been numerous studies showing the therapeutic benefits of chiropractic care.\nSciatica\n\nSciatica is a type of pain affecting the sciatic nerve, the large nerve extending from the low back down the back of the legs. Other natural therapies don?t always offer relief and most people want to avoid steroid injections and surgery, so they turn to chiropractic care.\n\nA double-blind trial reported in the Spine Journal compared active and simulated chiropractic manipulations in people with sciatic nerve pain. Active manipulations involved the patient laying down and receiving treatment from a chiropractor. Stimulated manipulations involved electrical muscle stimulation with electrodes placed on the skin to send electrical pulses to different parts of the body.\n\nThe researchers determined active manipulation offered more benefits than stimulated. The people who received active manipulations experienced fewer days of moderate or severe pain and other sciatica symptoms. They also reported no adverse effects.\nNeck Pain\n\nOne study reported in the Annals of Internal Medicine looked at different therapies for treating neck pain. They divided 272 study participants into three groups: one that received spinal manipulation from a chiropractic doctor, a second group given over-the-counter (OTC) pain relievers, narcotics, and muscle relaxers, and a third group who did at-home exercises. \n\nAfter 12 weeks, patients reported a 75% pain reduction, with the chiropractic treatment group achieving the most improvement. About 57% of the chiropractic group achieved pain reduction, while 48% received pain reduction from exercising, and 33% from medication.\n\nAfter one year, 53% of the drug-free groups continued to report pain relief compared to only 38% of those taking pain medications. \nHeadaches\n\nCervicogenic headaches and migraines are commonly treated by chiropractors. Cervicogenic headaches are often called secondary headaches because pain is usually referred from another source, usually the neck. Migraine headaches cause severe, throbbing pain and are generally experienced on one side of the head. There are few non-medicinal options for managing both types of chronic headaches.\n\nResearch reported in the Journal of Manipulative and Physiological Therapeutics suggests chiropractic care, specifically spinal manipulation, can improve migraines and cervicogenic headaches.  \nFrozen Shoulder\n\nFrozen shoulder affects the shoulder joint and involves pain and stiffness that develops gradually and gets worse. Frozen shoulder can be quite painful, and treatment involves preserving as much range of motion in the shoulder as possible and managing pain.\n\nA clinical trial reported in the Journal of Chiropractic Medicine described how patients suffering from frozen shoulder responded to chiropractic treatment. Of the 50 patients, 16 completely recovered, 25 showed a 75 to 90% improvement, and eight showed a 50 to 75% improvement. Only one person showed zero to 50% improvement. The researchers concluded most people can get improvement by treating frozen shoulder with chiropractic treatment.\nPreventing Need for Surgery\n\nChiropractic care may reduce the need for back surgery. Guidelines reported in the Journal of the American Medical Association suggest that it's reasonable for people suffering from back pain to try spinal manipulation before deciding on surgical intervention.\nLow Back Pain\n\nStudies have shown chiropractic care, including spinal manipulation, can provide relief from mild to moderate low back pain. In fact, spinal manipulation may work as well as other standard treatments, including pain-relief medications.\n\nA 2011 review of 26 clinical trials looked at the effectiveness of different treatments for chronic low back pain. What they found was that spinal manipulation is just as effective as other treatments for reducing back pain and improving function.\nSafety\n\n\nWhen chiropractors are correctly trained and licensed, chiropractic care is safe. Mild side effects are to be expected and include temporary soreness, stiffness, and tenderness in the treated area. However, you still want to do your research. Ask for a referral from your doctor. Look at the chiropractor?s website, including patient reviews. Meet with the chiropractor to discuss his or her treatment practices and ask about possible adverse effects related to treatment.\n\nIf you decide a chiropractor isn?t for you, consider seeing an osteopathic doctor. Osteopaths are fully licensed doctors who can practice all areas of medicine. They have received special training on the musculoskeletal system, which includes manual readjustments, myofascial release and other physical manipulation of bones and muscle tissues.
## 4 Advanced Chiropractic Relief: 8 Key Benefits of Chiropractor Care\n\nAre you one of the 50 million Americans who suffer from chronic pain? If so you?re probably intimately familiar with the feeling of pure desperation that can arise from an inability to find relief.\n\nIn addition to physical issues, chronic pain can cause anxiety, depression, and more. However, there could be a light at the end of the tunnel. Many people are finding advanced chiropractic relief that is completely changing their lives.\n\nYour body is a world in itself. At this very moment, more than a million chemical reactions are taking place in your body. It manufactures energy, it regulates your heartbeat, your breathing and it regenerates and heals itself. Everything takes place without your conscious knowledge, without you controlling it voluntarily. The master system that controls it all is your nervous system.\n\nThe nervous system is made out of your brain, spinal cord and all your nerves.\n\nThe energy that flows through your nervous system in your body is like electricity. In order to have that electric flow normally and freely, we need to have a well functioning spine. Whenever you have disruption of that flow, disease happens. That would be the case when your spine is misaligned or is not moving properly.\n\nDid you know that 90% of stimulation and nutrition to the brain is generated by the movement of the spine?\n\nThe more mechanically distorted a person is, the less energy is available for thinking, metabolism and healing.\n\nThis is why it is so important to have a healthy spine, a proper posture, to exercise, to eat properly ? all of it truly matters for your quality of life.\nChiropractors localize the areas of your spine that do not move properly ? referred to as vertebral subluxations ? and adjust them with a specific high speed, but yet gentle, thrust to improve spinal motion.\n\nWant to learn about some of the ways chiropractic care can help you? Keep reading for insight into some of the key benefits of seeing a chiropractor.\n\nThe benefits of chiropractic care are numerous:\n\n1. Lower Blood Pressure\n\nStudies show that chiropractic treatment can lower your blood pressure. Sometimes, this works just as well as a prescription blood pressure medication! This benefit can also last for as long as six months after treatment.\n\nHigh blood pressure can cause an array of serious side effects like nausea, fatigue, dizziness, and anxiety. Sufferers who haven?t found relief should consider consulting with a chiropractor. A chiropractic adjustment may be the solution.\n\nSome studies have shown that chiropractic adjustments can also help patients who are suffering from low blood pressure.\n\n2. Reduced Inflammation\n\nIn many cases, joint issues, pain, and tension are caused by inflammation in the body. Chiropractic adjustments can reduce inflammation.\n\nThis leads to relief of muscle tension, chronic back pain, and joint pain. These adjustments can sometimes also slow the progression of inflammation-related diseases, like arthritis.\n\n3. Better Sleep\n\nPatients who receive chiropractic adjustments report a significant improvement in their sleep patterns. If you regularly suffer from insomnia, visiting a chiropractor regularly may help. Also, when you experience pain relief, this will help you get a restful night?s sleep.\n\n4. Digestive Relief\n\nChiropractors often give nutritional advice as part of their services. However, this isn?t the only way that they provide patients with digestive relief.\n\nAdjusting the thoraco-lumbar spine restores the neurological function of your digestive system. Regular adjustments can help with chronic digestive issues.\n\n5. Stress Release\n\nEveryday life can cause muscle cramping, inflammation, and more. When you?re sore from working at a computer, heavy lifting, or just dealing with emotional stress, a chiropractic adjustment can help. This leads to greater comfort and advanced pain relief.\n\n6. Improvement of Neurological Conditions\n\nA chiropractic adjustment can also increase blood flow to the brain and increase the flow of cerebral spinal fluid. This means that patients suffering from neurological conditions like epilepsy and multiple sclerosis can significantly benefit from regular adjustments.\n\nThis is a relatively new area of study, but the potential is huge. Those suffering from these conditions will want to do some research. It?s important to find the best chiropractor in their area with experience dealing with these specific types of cases.\n\n7. Chiropractic care can improve communication from your brain to your muscles\n\nResearch seems to show that chiropractic care can improve your brain-body communication, helping your brain to be more aware of what is going on in the body so it can control your body better.\n\nBetter health, more energy and vitality are some of the positive effects of getting your spine adjusted. It sets your vertebrae back into motion freeing up the energy that travels through your nerves.\n\nChiropractic care is a partnership. The results patients want is a combination of what the chiropractor does and what the patient does.\n\nThere are many good things that can be changed and improved for a better lifestyle: exercise, good nutrition, good mental attitude and spinal adjustments.\n\nYour whole body will work better by having your nervous system free of interference. That is the essence of chiropractic care and is designed for you and your family.\n\n8. Pain Relief\n\nPerhaps the most well-known benefit of going to a chiropractor is pain relief. Adjustments can help with a huge array of painful conditions including the following.\n\nNeck and Lower Back Pain\n\nAdjustments are the most effective non-invasive pain relief method for this type of pain. They may help patients avoid having to take prescription pain management drugs.\n\nSciatica\n\nTreatments help relieve pressure on the nerve. This results in less severe pain that lasts for a fewer number of days.\n\nHeadaches\n\nChiropractic adjustments help headaches and migraines. They do this by treating back misalignment, muscle tension, and stress. Cervical spine manipulation was associated with significant improvement in headache outcomes in trials involving patients with neck pain and/or neck dysfunction and headache.\n\nChronic headaches can result from the abnormal positioning of the head and can be worsened from neck pressure and movement. Chiropractic removes the interference whether it may be from the distant muscle tightness in the back causing strain on your spine or an abnormal lordotic cervical curve and moving vertebrae.\nChiropractic care can reduce the duration of headaches, lower their intensity when they do occur and limit the frequency of their occurrence all together.\n\nMenstrual cramps\n\nChiropractic treatment removes tension from the pelvis and sacrum. It also regulates the neurological function communicating with the reproductive organs. Adjustments can also relieve the bloating, cramping, and pain associated with menstrual cramps\n\nAnyone who has tried traditional medical treatments and has been unable to find pain relief should experiment with chiropractic care. More often than not, you?ll be pleasantly surprised!\n\nBonus: Advanced Chiropractic Relief\n\nIn addition to the benefits listed above, adjustments can bring advanced chiropractic relief for a wide variety of other conditions as well as overall life improvement. A few examples include:\n\nScoliosis ? adjustments have shown to help with the pain, reduced range of motion, abnormal posture, and even difficulty breathing caused by this abnormal curvature of the spine\n\nVertigo ? an adjustment can help realign and balance the spine, thereby reducing the dizziness, nausea, and disorientation caused by vertigo\n\nSinus and allergy relief ? adjusting the upper cervical spine can help drain the sinuses and provide immediate and lasting relief from both long-term and seasonal allergies\n\nExpectant mothers ? women can experience relief from pain and morning sickness and are better able to maintain proper posture during and after pregnancy\n\nChildren?s issues ? treatments have been shown to help children with acid reflux, cholic, and ear infections\nAthletic performance ? the reduction in pain and inflammation is particularly beneficial for professional and amateur athletes\n\nStimulates the immune system ? chiropractic care helps to boost the immune system, speeding up the healing process following illnesses or injuries. One of the most important studies showing the positive effect chiropractic care can have on the immune system and general health was performed by Ronald Pero, Ph.D., chief of cancer prevention research at New York?s Preventive Medicine Institute and professor of medicine at New York University. Dr. Pero measured the immune systems of people under chiropractic care as compared to those in the general population and those with cancer and other serious diseases.\n\nIn his initial three-year study of 107 individuals who had been under chiropractic care for five years or more, the chiropractic patients were found to have a 200% greater immune competence than people who had not received chiropractic care, and 400% greater immune competence than people with cancer and other serious diseases. The immune system superiority of those under chiropractic care did not diminish with age.\n\nDr. Pero stated: ?When applied in a clinical framework, I have never seen a group other than this chiropractic group to experience a 200% increase over the normal patients. This is why it is so dramatically important. We have never seen such a positive improvement in a group.?\n\nAs you can see, there are almost limitless benefits to seeking chiropractic treatment. If you haven?t tried it yet, what are you waiting for?\n\nThere?s no need to accept pain and discomfort as a normal part of life. You have nothing to lose and everything to gain, so it only makes sense to find out more about this possibly life-changing approach to improving your health and wellness.
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             Heading to the spa can be a pampering treat, but it can also be a huge boost to your health and wellness! Massage therapy can relieve all sorts of ailments ? from physical pain, to stress and anxiety. People who choose to supplement their healthcare regimen with regular massages will not only enjoy a relaxing hour or two at the spa, but they will see the benefits carry through the days and weeks after the appointment!\n\n1\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\nThese are the 10 most common benefits reported from massage therapy:\n\n1. Reduce Stress\n\nA relaxing day at the spa is a great way to unwind and de-stress. However, clients are sure to notice themselves feeling relaxed and at ease for days and even weeks after their appointments!\n\n \n\n2. Improve Circulation\n\nLoosening muscles and tendons allows increased blood flow throughout the body. Improving your circulation can have a number of positive effects on the rest of your body, including reduced fatigue and pain management!\n\n \n\n3. Reduce Pain\n\nMassage therapy is great for working out problem areas like lower back pain and chronic stiffness. A professional therapist will be able to accurately target the source of your pain and help achieve the perfect massage regimen.\n\n \n\n3\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n4. Eliminate Toxins\n\nStimulating the soft tissues of your body will help to release toxins through your blood and lymphatic systems.\n\n \n\n5. Improve Flexibility\n\nMassage therapy will loosen and relax your muscles, helping your body to achieve its full range of movement potential.\n\n \n\n6. Improve Sleep\n\nA massage will encourage relaxation and boost your mood.  Going to bed with relaxed and loosened muscles promotes more restful sleep, and you?ll feel less tired in the morning!\n\n \n\n7. Enhance Immunity\n\nStimulation of the lymph nodes re-charges the body?s natural defense system.\n\n \n\n8. Reduce Fatigue\n\nMassage therapy is known to boost mood and promote better quality sleep, thus making you feel more rested and less worn-out at the end of the day.\n\n \n\n2\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n9. Alleviate Depression and Anxiety\n\nMassage therapy can help to release endorphins in your body, helping you to feel happy, energized, and at ease.\n\n \n\n10. Reduce post-surgery and post-injury swelling\n\nA professional massage is a great way to safely deal with a sports injury or post-surgery rehabilitation.\n\nDo you think that massage therapy could help you find relief in any of these areas? What improvements would you like to see in your health? Contact us today with your questions about massage therapy and see how we can help you get on the path to improved health and wellness!
## 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Massage: Get in touch with its many benefits\n\nMassage can be a powerful tool to help you take charge of your health and well-being. See if it's right for you.\nBy Mayo Clinic Staff\n\nMassage is no longer available only through luxury spas and upscale health clubs. Today, massage therapy is offered in businesses, clinics, hospitals and even airports. If you've never tried massage, learn about its possible health benefits and what to expect during a massage therapy session.\nWhat is massage?\n\nMassage is a general term for pressing, rubbing and manipulating your skin, muscles, tendons and ligaments. Massage may range from light stroking to deep pressure. There are many different types of massage, including these common types:\n\n    Swedish massage. This is a gentle form of massage that uses long strokes, kneading, deep circular movements, vibration and tapping to help relax and energize you.\n    Deep massage. This massage technique uses slower, more-forceful strokes to target the deeper layers of muscle and connective tissue, commonly to help with muscle damage from injuries.\n    Sports massage. This is similar to Swedish massage, but it's geared toward people involved in sport activities to help prevent or treat injuries.\n    Trigger point massage. This massage focuses on areas of tight muscle fibers that can form in your muscles after injuries or overuse.\n\nBenefits of massage\n\nMassage is generally considered part of complementary and integrative medicine. It's increasingly being offered along with standard treatment for a wide range of medical conditions and situations.\n\nStudies of the benefits of massage demonstrate that it is an effective treatment for reducing stress, pain and muscle tension.\n\nWhile more research is needed to confirm the benefits of massage, some studies have found massage may also be helpful for:\n\n    Anxiety\n    Digestive disorders\n    Fibromyalgia\n    Headaches\n    Insomnia related to stress\n    Myofascial pain syndrome\n    Soft tissue strains or injuries\n    Sports injuries\n    Temporomandibular joint pain\n\nBeyond the benefits for specific conditions or diseases, some people enjoy massage because it often produces feelings of caring, comfort and connection.\n\nDespite its benefits, massage isn't meant as a replacement for regular medical care. Let your doctor know you're trying massage and be sure to follow any standard treatment plans you have.\nRisks of massage\n\n\n\nSome forms of massage can leave you feeling a bit sore the next day. But massage shouldn't ordinarily be painful or uncomfortable. If any part of your massage doesn't feel right or is painful, speak up right away. Most serious problems come from too much pressure during massage.\nWhat you can expect during a massage\n\nYou don't need any special preparation for massage. Before a massage therapy session starts, your massage therapist should ask you about any symptoms, your medical history and what you're hoping to get out of massage. Your massage therapist should explain the kind of massage and techniques he or she will use.\n\nIn a typical massage therapy session, you undress or wear loose-fitting clothing. Undress only to the point that you're comfortable. You generally lie on a table and cover yourself with a sheet. You can also have a massage while sitting in a chair, fully clothed. Your massage therapist should perform an evaluation through touch to locate painful or tense areas and to determine how much pressure to apply.\n\nDepending on preference, your massage therapist may use oil or lotion to reduce friction on your skin. Tell your massage therapist if you might be allergic to any ingredients.\n\nA massage session may last from 10 to 90 minutes, depending on the type of massage and how much time you have. No matter what kind of massage you choose, you should feel calm and relaxed during and after your massage.\n\nIf a massage therapist is pushing too hard, ask for lighter pressure. Occasionally you may have a sensitive spot in a muscle that feels like a knot. It's likely to be uncomfortable while your massage therapist works it out. But if it becomes painful, speak up.\nFinding a massage therapist\n\nAsk your doctor or someone else you trust for a recommendation. Most states regulate massage therapists through licensing, registration or certification requirements.\n\nDon't be afraid to ask a potential massage therapist such questions as:\n\n    Are you licensed, certified or registered?\n    What is your training and experience?\n    How many massage therapy sessions do you think I'll need?\n    What's the cost, and is it covered by health insurance?\n\nThe take-home message about massage\n\nBrush aside any thoughts that massage is only a feel-good way to indulge or pamper yourself. To the contrary, massage can be a powerful tool to help you take charge of your health and well-being, whether you have a specific health condition or are just looking for another stress reliever. You can even learn how to do self-massage or how to engage in massage with a partner at home. 
##                   Topic
## 1 chiropractic benefits
## 2 chiropractic benefits
## 3 chiropractic benefits
## 4 chiropractic benefits
## 5      massage benefits
## 6      massage benefits

We are to make our data table into a dplyr tibble.

text_df <- tibble(line=1:87, text=modalities1$Document,
                  Recommend=modalities1$Topic)
head(text_df)
## # A tibble: 6 x 3
##    line text                                                   Recommend        
##   <int> <fct>                                                  <fct>            
## 1     1 "Chiropractic adjustments and treatments serve the ne~ chiropractic ben~
## 2     2 "\nUnitedHealthcare Combats Opioid Crisis with Non-Op~ chiropractic ben~
## 3     3 " The Safety of Chiropractic Adjustments\nBy Lana Bar~ chiropractic ben~
## 4     4 "Advanced Chiropractic Relief: 8 Key Benefits of Chir~ chiropractic ben~
## 5     5 "Heading to the spa can be a pampering treat, but it ~ massage benefits 
## 6     6 "Massage: Get in touch with its many benefits\n\nMass~ massage benefits

Now for the word counts by line or in our case by review which is line.This uses the tidytext package to unnest the words as tokens from each review. We will use the ngrams method of tokenizing to get the sequential groups of threes for words used in combination. This will be very useful to us in predicting our ratings accurately. As we have seen that using a word like ‘like’ or ‘good’ has very similar word counts in ratings of 1 and ratings of 5 but not so much in the 2-4 range. This is because some of those likes are in ngrams of 2-3 with word pairings such as ‘don’t like’, ‘not as good’, etc.

text_df$text <- as.character(paste(text_df$text))

fills <- as.data.frame(c('of','the','a','an','in','by','it','as','or','go','goes','am','and','to'))
colnames(fills) <- 'fillers'

text_df0 <- text_df %>% unnest_tokens(bigram,text,token='ngrams',n=2) %>%
  separate(bigram, c('word1','word2'), sep=' ') 

text_df01 <- anti_join(text_df0,fills, by=c("word1"="fillers"))
text_df02 <- anti_join(text_df01,fills, by=c("word2"="fillers"))

text_df02$bigram <- paste(text_df02$word1,text_df02$word2,sep=' ')
text_df03 <- text_df02[,-c(2:4)]

text_df1 <- text_df %>% unnest_tokens(bigram,text, token='ngrams',n=2)
text_df2 <- merge(text_df1,text_df03, by.x='bigram', by.y='bigram', all.y=FALSE)

text_df3 <- text_df2[,-4]
colnames(text_df3)[2] <- 'line'
head(text_df3,30)
##                                                                                     bigram
## 1   _______________________________________________________________________________ damkee
## 2    _______________________________________________________________________________ mebak
## 3  _______________________________________________________________________________ sylphim
## 4                                                                                      0 6
## 5                                                                               0 comments
## 6                                                                                  01 03pm
## 7                                                                                  02 2013
## 8                                                                                  02 2019
## 9                                                                                  02 2020
## 10                                                                           02 futuristic
## 11                                                                                   03 02
## 12                                                                                 03 2020
## 13                                                                                03pm edt
## 14                                                                                   04 30
## 15                                                                                   05 02
## 16                                                                     0586344522 remember
## 17                                                                                  1 2019
## 18                                                                                     1 5
## 19                                                                                     1 5
## 20                                                                                     1 5
## 21                                                                                     1 5
## 22                                                                                     1 5
## 23                                                                                     1 5
## 24                                                                                     1 5
## 25                                                                                     1 5
## 26                                                                                     1 5
## 27                                                                                     1 8
## 28                                                                                   1 800
## 29                                                                                   1 877
## 30                                                                              1 diabetes
##    line                       Recommend
## 1    54            massage gun benefits
## 2    54            massage gun benefits
## 3    54            massage gun benefits
## 4    27 mental health services benefits
## 5    27 mental health services benefits
## 6    49            massage gun benefits
## 7    62             cold stone benefits
## 8    36                cupping benefits
## 9    28 mental health services benefits
## 10   51            massage gun benefits
## 11   62             cold stone benefits
## 12   31 mental health services benefits
## 13   49            massage gun benefits
## 14   49            massage gun benefits
## 15   51            massage gun benefits
## 16   69                Not Professional
## 17   50            massage gun benefits
## 18   51            massage gun benefits
## 19   51            massage gun benefits
## 20   51            massage gun benefits
## 21   85                              ER
## 22   85                              ER
## 23   85                              ER
## 24   85                              ER
## 25   85                              ER
## 26   85                              ER
## 27   27 mental health services benefits
## 28   30 mental health services benefits
## 29   30 mental health services benefits
## 30   10                massage benefits

We see from the above it basically goes along every string word and counts each white space to separate a character from a non-character and get each word, but it also does it for any three combinations, so that almost every word is part of the beginning of one trigram (as we set n to 3 for the number of ngrams, thus trigram), the middle of one trigram, or the end of a trigram. Look at ‘wonderful’ above and see what I am referring to.

text_df4 <- text_df3 %>% group_by(bigram) %>% count(bigram, sort=TRUE) %>% ungroup
head(text_df4,30)
## # A tibble: 30 x 2
##    bigram               n
##    <chr>            <int>
##  1 mental health    25281
##  2 physical therapy 11236
##  3 massage gun       9409
##  4 massage therapy   7744
##  5 if you            7225
##  6 massage guns      6241
##  7 can be            5625
##  8 can help          5041
##  9 you can           3600
## 10 stone massage     3249
## # ... with 20 more rows

The above shows all documents bigram occurences of word pairs.

We want the recommended modality or health care option for each category counts of bigrams.

er <- subset(text_df3, text_df3$Recommend=='ER')
nonPro <- subset(text_df3, text_df3$Recommend=='Not Professional')
chiropractor <- subset(text_df3, text_df3$Recommend=='chiropractic benefits')
massage <- subset(text_df3, text_df3$Recommend=='massage benefits')
physicalTherapy <- subset(text_df3, text_df3$Recommend=='physical therapy benefits')
mental <- subset(text_df3, text_df3$Recommend=='mental health services benefits')
cupping <- subset(text_df3, text_df3$Recommend=='cupping benefits')
massageGun <- subset(text_df3, text_df3$Recommend=='massage gun benefits')
coldStone <- subset(text_df3, text_df3$Recommend=='cold stone benefits')

Group each category into bigram counts.

er2 <- er %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
er3 <- spread(er2,bigram,n)
freqER <- colSums(er3)

nonPro2 <- nonPro %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
nonPro3 <- spread(nonPro2,bigram,n)
freqNonPro <- colSums(nonPro3)

chiropractor2 <- chiropractor %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
chiropractor3 <- spread(chiropractor2,bigram,n)
freqChiropractor <- colSums(chiropractor3)

massage2 <- massage %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
massage3 <- spread(massage2,bigram,n)
freqMassage <- colSums(massage3)

physical2 <- physicalTherapy %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
physical3 <- spread(physical2,bigram,n)
freqPhysical <- colSums(physical3)

mental2 <- mental %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
mental3 <- spread(mental2,bigram,n)
freqMental <- colSums(mental3)

cupping2 <- cupping %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
cupping3 <- spread(cupping2,bigram,n)
freqCupping <- colSums(cupping3)

massageGun2 <- massageGun %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
massageGun3 <- spread(massageGun2,bigram,n)
freqMassageGun <- colSums(massageGun3)

coldStone2 <- coldStone %>% group_by(bigram) %>% count(bigram, sort=TRUE) 
coldStone3 <- spread(coldStone2,bigram,n)
freqColdStone <- colSums(coldStone3)
wordcloud(names(freqER), freqER,
          min.freq=10,colors=brewer.pal(3,'Dark2'))

wordcloud(names(freqNonPro), freqNonPro,
          min.freq=5,colors=brewer.pal(3,'Dark2'))
## Warning in wordcloud(names(freqNonPro), freqNonPro, min.freq = 5, colors =
## brewer.pal(3, : massage therapist could not be fit on page. It will not be
## plotted.

The above shows most bigrams or double word pairings in the non-professional services category.

wordcloud(names(freqChiropractor), freqChiropractor,
          min.freq=80,colors=brewer.pal(3,'Dark2'))
## Warning in wordcloud(names(freqChiropractor), freqChiropractor, min.freq = 80, :
## chiropractic care could not be fit on page. It will not be plotted.

The above word cloud shows the top frequency bigram word pairs for chiropractic services.

wordcloud(names(freqMassage), freqMassage, min.freq=100,colors=brewer.pal(3,'Dark2'))
## Warning in wordcloud(names(freqMassage), freqMassage, min.freq = 100, colors
## = brewer.pal(3, : massage therapy could not be fit on page. It will not be
## plotted.

The above word cloud is for massage therapy services word pairs used most often.

wordcloud(names(freqPhysical), freqPhysical,
          min.freq=80,colors=brewer.pal(3,'Dark2'))
## Warning in wordcloud(names(freqPhysical), freqPhysical, min.freq = 80, colors
## = brewer.pal(3, : physical therapy could not be fit on page. It will not be
## plotted.

The above word cloud is the bigram word pairs used in physical therapy services documents in the data.

wordcloud(names(freqMental), freqMental,
          min.freq=80,colors=brewer.pal(3,'Dark2'))

The above word cloud is for word pairs used frequently in mental health documents.

wordcloud(names(freqCupping), freqCupping,
          min.freq=80,colors=brewer.pal(3,'Dark2'))
## Warning in wordcloud(names(freqCupping), freqCupping, min.freq = 80, colors
## = brewer.pal(3, : cupping therapy could not be fit on page. It will not be
## plotted.

The above word cloud is for cupping therapy services.

wordcloud(names(freqMassageGun), freqMassageGun,
          min.freq=80,colors=brewer.pal(3,'Dark2'))

The above word cloud is for the massage gun services bigram word pairings in our documents on that category.

wordcloud(names(freqColdStone), freqColdStone,
          min.freq=80,colors=brewer.pal(3,'Dark2'))

This last word cloud above is for cold stone massage therapy bigram word pairs in the documents on cold stone therapy benefits and contraindications.

Looking forward to improving this recommendation system for healthcare services, we need to test these vectorizations, TF-IDF and N-grams, on the previous dataset withou scrubbed risks and without the ER added class and see how well the results produced get towards 100% accuracy. Also, maybe adding in longer inputs for the Non Professional services, but there is a huge caveat of digging into offensive domain territory and being exposed to non-professional and vagrant smut in the process that could open this source to computer virus attacks or inappropriate recommender systems based on the cookies stored when visiting those sites. The latter could be prevented by deleting cookies and browsing private, but the exposure to offensive materials exists in scrubbing the web of longer document content to fill the Non Professional services category, so that the short user inputs won’t keep classifying them as ‘Non Professional Services’ when clearly some are options for massage gun, chiroprator, ER, or physical therapy.

Another approach would be to take those words that are useful or beneficial to each healthcare service as a recommendation, without the filler content and then make a list of those risks and contraindications for each class of healthcare services or non-professional services. Then in those lists, when the user input is short and concise, the list of options to choose from will be calculated as the option with the highest probability, and if the user separately lists in a different user input any health problems and/or symptoms as a list, then that could choose to knock out the healthcare services that those symptoms are a contraindication for. Such as, if a user says they have pain in their back, but can’t sleep because of the pain, have been feeling overheated, have a history of seizures, and maybe is nautious, then the first recommnder will recommend massage, physical therapy, or any other professional healthcare services, but once the user puts in the list of symptoms, the massage and possibly chiropractic and non-professional services would be eliminated leaving only the recommendation for ER services, chiropractic, or physical therapy healthcare services.

Another option to add to the above, is to use the single word or ngrams equal to one word clouds and eliminating stopwords.


Lets see what the single standout words are in this wordcloud. Lets read in the csv file if you don’t have it stored as Reviews15_results.

modalities <- read.csv('benefitsContraindications3.csv',
                              sep=',', header=TRUE, na.strings=c('',' ','NA'))
colnames(modalities)
## [1] "Document"            "Source"              "Topic"              
## [4] "InternetSearch"      "Contraindications"   "risksAdverseEffects"

Lets just use the userReviewOnlyContent and the userRatingValue columns.

modalities1 <- modalities[,c(1,3)]
head(modalities1)
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Document
## 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Chiropractic adjustments and treatments serve the needs of millions of people around the world.\n\n \n\nAdjustments offer effective, non-invasive and cost-effective solutions to neck and back pain, as well as a myriad of other medical issues.\n\nHave you ever stopped to wonder how many of us suffer from neck and back stiffness or pain?\n\nApart from the obvious discomfort, simple daily tasks such as driving a car, crossing a busy street and picking things up from the floor can become all too challenging for individuals experiencing such pain.\n\nAs anyone who has experienced pain would know, having restricted movement can be debilitating and unfortunately, our busy world doesn?t allow for us to stop.\n\n \nSome of the benefits of long-term chiropractic care include:\n\n    Chiropractors can identify mechanical issues that cause spine-related pain and offer a series of adjustments that provide near immediate relief. Following appointments, patients often report feeling their symptoms noticeably better.\n    When a chiropractor performs an adjustment, they can help restore movement in joints that have ?locked up?. This becomes possible as treatment allows muscles surrounding joints to relax, thereby reducing joint stiffness.\n    Many factors affect health, including exercise patterns, nutrition, sleep, heredity and the environment in which we live. Rather than just treat symptoms of the disease, chiropractic care focuses on a holistic approach to naturally maintain health and resist disease.\n    Chiropractic adjustments help restore normal function and movement to the entire body. Many patients report an improvement in their ability to move with efficiency and strength.\n    Many patients find delight in the results chiropractic adjustments have on old and chronic injuries. Whether an injury is, in fact, new or old, chiropractic care can help reduce pain, restore mobility and provide quick pain relief to all joints in the body. Such care can help maintain better overall health and thus faster recovery time.\n\nHave you ever noticed that when you are in pain and unable to perform regular or favorite activities, it can put a strain on emotional and mental well-being?\n\nFor example, the increased stress from not being able to properly perform a paid job. This, in turn, can have a negative impact on physical health with increases in heart rate and blood pressure. The domino effect often continues with sleep becoming disturbed, with resulting lethargy and tiredness during the day. Does anyone really feel up to exercising in this state?\n\nChiropractic care is a natural method of healing the body?s communication system and never relies on the use of pharmaceutical drugs or invasive surgery.\n\nDoctors of Chiropractic work collaboratively with other healthcare professionals. Should your condition require the attention of another healthcare profession, that recommendation or referral will be made.\n\n 
## 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    \nUnitedHealthcare Combats Opioid Crisis with Non-Opioid Benefits\nPhysical therapy and chiropractic care can prevent or reduce expensive, invasive spinal procedures, such as imaging or surgery, to reduce opioid use and cut costs.\nUnitedHealthcare, opioid, physical therapy, healthcare spending\n\nSource: Thinkstock\nShare on Twitter\n\nBy Kelsey Waddill\n\nOctober 29, 2019 - UnitedHealthcare (UHC) is combatting the opioid epidemic and high healthcare costs with new physical therapy and chiropractic care benefits to prevent, delay, or in some cases substitute for invasive spinal procedures.\n\n?With millions of Americans experiencing low back pain currently or at some point during their lifetimes, we believe this benefit design will help make a meaningful difference by improving health outcomes while reducing costs,? said Anne Docimo, MD, UnitedHealthcare chief medical officer.\n\nLower back pain is in part responsible for sustaining the opioid epidemic and also increases healthcare costs.\nDig Deeper\n\n    How Major Payers Provide Substance Abuse Care for Opioid Misuse\n    Opioid Overdoses Fall by 2% from 2017 to 2018, CDC Reports\n    Physical Therapy, Chiropractic Back Care Cut Opioid Use, Costs\n\nAlthough opioid overdoses fell by two percent from 2017 to 2018 and a legal battles aim to hold pharmaceutical companies accountable, there is no end in sight for the opioid epidemic. Industry professionals are still grappling with the balance between cutting opioid prescriptions will working to reduce patient pain.\n\nCommon conditions such as low back pain bolster the epidemic?s presence, with clinicians still prescribing the opioids against best practice recommendations. According to a recent OptumLabs study, 9 percent of patients with newly diagnosed low back pain are prescribed opioids and lower back pain currently contributes 52 percent to the overall opioid prescription rate.\n\nIn addition to boosting opioids distribution, alternative, invasive lower back pain treatments can significantly impact healthcare spending.\n\nIt is not new information that physical therapy and chiropractic care are effective, lower cost alternatives to spinal imaging or surgery. However, payers are still in the process of adopting the method.\n\nTo counteract the high-cost, high-risk potential of using opioids to treat back pain, UHC created a benefit that does not rely on medication or technology but rather on physical therapy and chiropractic care.\n\nThe benefit allows eligible employers to offer physical therapist and chiropractor visits with no out-of-pocket costs. Members who already receive physical therapist and chiropractic care benefits under UHC?s employer-sponsored health plans and who have maxed out their visits will not receive additional visits under this benefit.\n\nHowever, for those who still have visits to use and who choose physical therapy or chiropractic care over other forms of treatment, the copay or deductible for those visits will be waived and they will receive three visits at no cost.\n\nUHC has high expectations for the fiscal and physical impacts of this benefit.\n\nAccording to UHC?s analysis, the health payer expects that by 2021, opioid use will decrease by 19 percent. Spinal imaging test frequency and spinal surgeries will be reduced by 22 percent and 21 percent, respectively. In addition to these specific goals, UHC hopes to see a decrease in the overall cost of spinal care.\n\nThe same OptumLabs study demonstrated that UHC?s expectations are not without precedent.\n\nThe study looked at the correlation between out-of-pocket costs and patient utilization of noninvasive treatments. Researchers discovered that members whose copay was over $30 were a little under 30 percent less likely to choose physical therapy as opposed to more invasive treatments.\n\nAn American Journal of Managed Care study in June 2019 found that patients with high deductibles, typically over $1,000, were less likely to visit physical therapy.\n\nEligible employers may be brand new or renewing their membership. They must be fully insured and over 51 or more employees strong. The benefit is currently available in Connecticut, Florida, Georgia, New York, and North Carolina.\n\nHowever, UHC plans to expand the benefit from 2020 into 2021. By the end of this expansion period, the benefit will also be available to self-funded employers and organizations with an employee population between 2 and 50. The benefit will span ten states, primarily in the southeast.\n\n?This new benefit design may help encourage people with low back pain to get the right care at the right time and in the right setting, helping expand access to evidence-based and more affordable treatments,? said Docimo.
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     The Safety of Chiropractic Adjustments\nBy Lana Barhum\nMedically reviewed by Richard N. Fogoros, MD\nUpdated on January 31, 2020\nOrthopedics\nMore in Orthopedics\n\n    Home Office Ergonomics\n    Sprains & Strains\n    Fractures & Broken Bones\n    Physical Therapy\n    Orthopedic Surgery\n    Osteoporosis\n    Pediatric Orthopedics\n    Sports Injuries\n\nView All\nIn This Article\n\n    Chiropractic Adjustment\n    What Research Shows\n    Safety\n\nChiropractic adjustment, also called spinal manipulation, is a procedure done by a chiropractor using the hands or small instruments to apply controlled force to a spinal joint. The goal is to improve spinal motion and physical function of the entire body. Chiropractic adjustment is safe when performed by someone who is properly trained and licensed to practice chiropractic care. Complications are rare, but they are possible. Learn more about both the benefits and risks.\nChiropractic adjustment\nVerywell / Brianna Gilmartin \nChiropractic Adjustment\n\nOne of the most important reasons people seek chiropractic care is because it is a completely drug-free therapy. Someone dealing with joint pain, back pain, or headaches might consider visiting a chiropractor.\n\nThe goal of chiropractic adjustment is to place the body into a proper position so the body can heal itself. Treatments are believed to reduce stress on the immune system, reducing the potential for disease. Chiropractic care aims to address the entire body, including a person?s ability to move, perform, and even think.\nWhat Research Shows\n\nMany people wonder how helpful chiropractic care is in treating years of trauma and poor posture. There have been numerous studies showing the therapeutic benefits of chiropractic care.\nSciatica\n\nSciatica is a type of pain affecting the sciatic nerve, the large nerve extending from the low back down the back of the legs. Other natural therapies don?t always offer relief and most people want to avoid steroid injections and surgery, so they turn to chiropractic care.\n\nA double-blind trial reported in the Spine Journal compared active and simulated chiropractic manipulations in people with sciatic nerve pain. Active manipulations involved the patient laying down and receiving treatment from a chiropractor. Stimulated manipulations involved electrical muscle stimulation with electrodes placed on the skin to send electrical pulses to different parts of the body.\n\nThe researchers determined active manipulation offered more benefits than stimulated. The people who received active manipulations experienced fewer days of moderate or severe pain and other sciatica symptoms. They also reported no adverse effects.\nNeck Pain\n\nOne study reported in the Annals of Internal Medicine looked at different therapies for treating neck pain. They divided 272 study participants into three groups: one that received spinal manipulation from a chiropractic doctor, a second group given over-the-counter (OTC) pain relievers, narcotics, and muscle relaxers, and a third group who did at-home exercises. \n\nAfter 12 weeks, patients reported a 75% pain reduction, with the chiropractic treatment group achieving the most improvement. About 57% of the chiropractic group achieved pain reduction, while 48% received pain reduction from exercising, and 33% from medication.\n\nAfter one year, 53% of the drug-free groups continued to report pain relief compared to only 38% of those taking pain medications. \nHeadaches\n\nCervicogenic headaches and migraines are commonly treated by chiropractors. Cervicogenic headaches are often called secondary headaches because pain is usually referred from another source, usually the neck. Migraine headaches cause severe, throbbing pain and are generally experienced on one side of the head. There are few non-medicinal options for managing both types of chronic headaches.\n\nResearch reported in the Journal of Manipulative and Physiological Therapeutics suggests chiropractic care, specifically spinal manipulation, can improve migraines and cervicogenic headaches.  \nFrozen Shoulder\n\nFrozen shoulder affects the shoulder joint and involves pain and stiffness that develops gradually and gets worse. Frozen shoulder can be quite painful, and treatment involves preserving as much range of motion in the shoulder as possible and managing pain.\n\nA clinical trial reported in the Journal of Chiropractic Medicine described how patients suffering from frozen shoulder responded to chiropractic treatment. Of the 50 patients, 16 completely recovered, 25 showed a 75 to 90% improvement, and eight showed a 50 to 75% improvement. Only one person showed zero to 50% improvement. The researchers concluded most people can get improvement by treating frozen shoulder with chiropractic treatment.\nPreventing Need for Surgery\n\nChiropractic care may reduce the need for back surgery. Guidelines reported in the Journal of the American Medical Association suggest that it's reasonable for people suffering from back pain to try spinal manipulation before deciding on surgical intervention.\nLow Back Pain\n\nStudies have shown chiropractic care, including spinal manipulation, can provide relief from mild to moderate low back pain. In fact, spinal manipulation may work as well as other standard treatments, including pain-relief medications.\n\nA 2011 review of 26 clinical trials looked at the effectiveness of different treatments for chronic low back pain. What they found was that spinal manipulation is just as effective as other treatments for reducing back pain and improving function.\nSafety\n\n\nWhen chiropractors are correctly trained and licensed, chiropractic care is safe. Mild side effects are to be expected and include temporary soreness, stiffness, and tenderness in the treated area. However, you still want to do your research. Ask for a referral from your doctor. Look at the chiropractor?s website, including patient reviews. Meet with the chiropractor to discuss his or her treatment practices and ask about possible adverse effects related to treatment.\n\nIf you decide a chiropractor isn?t for you, consider seeing an osteopathic doctor. Osteopaths are fully licensed doctors who can practice all areas of medicine. They have received special training on the musculoskeletal system, which includes manual readjustments, myofascial release and other physical manipulation of bones and muscle tissues.
## 4 Advanced Chiropractic Relief: 8 Key Benefits of Chiropractor Care\n\nAre you one of the 50 million Americans who suffer from chronic pain? If so you?re probably intimately familiar with the feeling of pure desperation that can arise from an inability to find relief.\n\nIn addition to physical issues, chronic pain can cause anxiety, depression, and more. However, there could be a light at the end of the tunnel. Many people are finding advanced chiropractic relief that is completely changing their lives.\n\nYour body is a world in itself. At this very moment, more than a million chemical reactions are taking place in your body. It manufactures energy, it regulates your heartbeat, your breathing and it regenerates and heals itself. Everything takes place without your conscious knowledge, without you controlling it voluntarily. The master system that controls it all is your nervous system.\n\nThe nervous system is made out of your brain, spinal cord and all your nerves.\n\nThe energy that flows through your nervous system in your body is like electricity. In order to have that electric flow normally and freely, we need to have a well functioning spine. Whenever you have disruption of that flow, disease happens. That would be the case when your spine is misaligned or is not moving properly.\n\nDid you know that 90% of stimulation and nutrition to the brain is generated by the movement of the spine?\n\nThe more mechanically distorted a person is, the less energy is available for thinking, metabolism and healing.\n\nThis is why it is so important to have a healthy spine, a proper posture, to exercise, to eat properly ? all of it truly matters for your quality of life.\nChiropractors localize the areas of your spine that do not move properly ? referred to as vertebral subluxations ? and adjust them with a specific high speed, but yet gentle, thrust to improve spinal motion.\n\nWant to learn about some of the ways chiropractic care can help you? Keep reading for insight into some of the key benefits of seeing a chiropractor.\n\nThe benefits of chiropractic care are numerous:\n\n1. Lower Blood Pressure\n\nStudies show that chiropractic treatment can lower your blood pressure. Sometimes, this works just as well as a prescription blood pressure medication! This benefit can also last for as long as six months after treatment.\n\nHigh blood pressure can cause an array of serious side effects like nausea, fatigue, dizziness, and anxiety. Sufferers who haven?t found relief should consider consulting with a chiropractor. A chiropractic adjustment may be the solution.\n\nSome studies have shown that chiropractic adjustments can also help patients who are suffering from low blood pressure.\n\n2. Reduced Inflammation\n\nIn many cases, joint issues, pain, and tension are caused by inflammation in the body. Chiropractic adjustments can reduce inflammation.\n\nThis leads to relief of muscle tension, chronic back pain, and joint pain. These adjustments can sometimes also slow the progression of inflammation-related diseases, like arthritis.\n\n3. Better Sleep\n\nPatients who receive chiropractic adjustments report a significant improvement in their sleep patterns. If you regularly suffer from insomnia, visiting a chiropractor regularly may help. Also, when you experience pain relief, this will help you get a restful night?s sleep.\n\n4. Digestive Relief\n\nChiropractors often give nutritional advice as part of their services. However, this isn?t the only way that they provide patients with digestive relief.\n\nAdjusting the thoraco-lumbar spine restores the neurological function of your digestive system. Regular adjustments can help with chronic digestive issues.\n\n5. Stress Release\n\nEveryday life can cause muscle cramping, inflammation, and more. When you?re sore from working at a computer, heavy lifting, or just dealing with emotional stress, a chiropractic adjustment can help. This leads to greater comfort and advanced pain relief.\n\n6. Improvement of Neurological Conditions\n\nA chiropractic adjustment can also increase blood flow to the brain and increase the flow of cerebral spinal fluid. This means that patients suffering from neurological conditions like epilepsy and multiple sclerosis can significantly benefit from regular adjustments.\n\nThis is a relatively new area of study, but the potential is huge. Those suffering from these conditions will want to do some research. It?s important to find the best chiropractor in their area with experience dealing with these specific types of cases.\n\n7. Chiropractic care can improve communication from your brain to your muscles\n\nResearch seems to show that chiropractic care can improve your brain-body communication, helping your brain to be more aware of what is going on in the body so it can control your body better.\n\nBetter health, more energy and vitality are some of the positive effects of getting your spine adjusted. It sets your vertebrae back into motion freeing up the energy that travels through your nerves.\n\nChiropractic care is a partnership. The results patients want is a combination of what the chiropractor does and what the patient does.\n\nThere are many good things that can be changed and improved for a better lifestyle: exercise, good nutrition, good mental attitude and spinal adjustments.\n\nYour whole body will work better by having your nervous system free of interference. That is the essence of chiropractic care and is designed for you and your family.\n\n8. Pain Relief\n\nPerhaps the most well-known benefit of going to a chiropractor is pain relief. Adjustments can help with a huge array of painful conditions including the following.\n\nNeck and Lower Back Pain\n\nAdjustments are the most effective non-invasive pain relief method for this type of pain. They may help patients avoid having to take prescription pain management drugs.\n\nSciatica\n\nTreatments help relieve pressure on the nerve. This results in less severe pain that lasts for a fewer number of days.\n\nHeadaches\n\nChiropractic adjustments help headaches and migraines. They do this by treating back misalignment, muscle tension, and stress. Cervical spine manipulation was associated with significant improvement in headache outcomes in trials involving patients with neck pain and/or neck dysfunction and headache.\n\nChronic headaches can result from the abnormal positioning of the head and can be worsened from neck pressure and movement. Chiropractic removes the interference whether it may be from the distant muscle tightness in the back causing strain on your spine or an abnormal lordotic cervical curve and moving vertebrae.\nChiropractic care can reduce the duration of headaches, lower their intensity when they do occur and limit the frequency of their occurrence all together.\n\nMenstrual cramps\n\nChiropractic treatment removes tension from the pelvis and sacrum. It also regulates the neurological function communicating with the reproductive organs. Adjustments can also relieve the bloating, cramping, and pain associated with menstrual cramps\n\nAnyone who has tried traditional medical treatments and has been unable to find pain relief should experiment with chiropractic care. More often than not, you?ll be pleasantly surprised!\n\nBonus: Advanced Chiropractic Relief\n\nIn addition to the benefits listed above, adjustments can bring advanced chiropractic relief for a wide variety of other conditions as well as overall life improvement. A few examples include:\n\nScoliosis ? adjustments have shown to help with the pain, reduced range of motion, abnormal posture, and even difficulty breathing caused by this abnormal curvature of the spine\n\nVertigo ? an adjustment can help realign and balance the spine, thereby reducing the dizziness, nausea, and disorientation caused by vertigo\n\nSinus and allergy relief ? adjusting the upper cervical spine can help drain the sinuses and provide immediate and lasting relief from both long-term and seasonal allergies\n\nExpectant mothers ? women can experience relief from pain and morning sickness and are better able to maintain proper posture during and after pregnancy\n\nChildren?s issues ? treatments have been shown to help children with acid reflux, cholic, and ear infections\nAthletic performance ? the reduction in pain and inflammation is particularly beneficial for professional and amateur athletes\n\nStimulates the immune system ? chiropractic care helps to boost the immune system, speeding up the healing process following illnesses or injuries. One of the most important studies showing the positive effect chiropractic care can have on the immune system and general health was performed by Ronald Pero, Ph.D., chief of cancer prevention research at New York?s Preventive Medicine Institute and professor of medicine at New York University. Dr. Pero measured the immune systems of people under chiropractic care as compared to those in the general population and those with cancer and other serious diseases.\n\nIn his initial three-year study of 107 individuals who had been under chiropractic care for five years or more, the chiropractic patients were found to have a 200% greater immune competence than people who had not received chiropractic care, and 400% greater immune competence than people with cancer and other serious diseases. The immune system superiority of those under chiropractic care did not diminish with age.\n\nDr. Pero stated: ?When applied in a clinical framework, I have never seen a group other than this chiropractic group to experience a 200% increase over the normal patients. This is why it is so dramatically important. We have never seen such a positive improvement in a group.?\n\nAs you can see, there are almost limitless benefits to seeking chiropractic treatment. If you haven?t tried it yet, what are you waiting for?\n\nThere?s no need to accept pain and discomfort as a normal part of life. You have nothing to lose and everything to gain, so it only makes sense to find out more about this possibly life-changing approach to improving your health and wellness.
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             Heading to the spa can be a pampering treat, but it can also be a huge boost to your health and wellness! Massage therapy can relieve all sorts of ailments ? from physical pain, to stress and anxiety. People who choose to supplement their healthcare regimen with regular massages will not only enjoy a relaxing hour or two at the spa, but they will see the benefits carry through the days and weeks after the appointment!\n\n1\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\nThese are the 10 most common benefits reported from massage therapy:\n\n1. Reduce Stress\n\nA relaxing day at the spa is a great way to unwind and de-stress. However, clients are sure to notice themselves feeling relaxed and at ease for days and even weeks after their appointments!\n\n \n\n2. Improve Circulation\n\nLoosening muscles and tendons allows increased blood flow throughout the body. Improving your circulation can have a number of positive effects on the rest of your body, including reduced fatigue and pain management!\n\n \n\n3. Reduce Pain\n\nMassage therapy is great for working out problem areas like lower back pain and chronic stiffness. A professional therapist will be able to accurately target the source of your pain and help achieve the perfect massage regimen.\n\n \n\n3\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n4. Eliminate Toxins\n\nStimulating the soft tissues of your body will help to release toxins through your blood and lymphatic systems.\n\n \n\n5. Improve Flexibility\n\nMassage therapy will loosen and relax your muscles, helping your body to achieve its full range of movement potential.\n\n \n\n6. Improve Sleep\n\nA massage will encourage relaxation and boost your mood.  Going to bed with relaxed and loosened muscles promotes more restful sleep, and you?ll feel less tired in the morning!\n\n \n\n7. Enhance Immunity\n\nStimulation of the lymph nodes re-charges the body?s natural defense system.\n\n \n\n8. Reduce Fatigue\n\nMassage therapy is known to boost mood and promote better quality sleep, thus making you feel more rested and less worn-out at the end of the day.\n\n \n\n2\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n9. Alleviate Depression and Anxiety\n\nMassage therapy can help to release endorphins in your body, helping you to feel happy, energized, and at ease.\n\n \n\n10. Reduce post-surgery and post-injury swelling\n\nA professional massage is a great way to safely deal with a sports injury or post-surgery rehabilitation.\n\nDo you think that massage therapy could help you find relief in any of these areas? What improvements would you like to see in your health? Contact us today with your questions about massage therapy and see how we can help you get on the path to improved health and wellness!
## 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Massage: Get in touch with its many benefits\n\nMassage can be a powerful tool to help you take charge of your health and well-being. See if it's right for you.\nBy Mayo Clinic Staff\n\nMassage is no longer available only through luxury spas and upscale health clubs. Today, massage therapy is offered in businesses, clinics, hospitals and even airports. If you've never tried massage, learn about its possible health benefits and what to expect during a massage therapy session.\nWhat is massage?\n\nMassage is a general term for pressing, rubbing and manipulating your skin, muscles, tendons and ligaments. Massage may range from light stroking to deep pressure. There are many different types of massage, including these common types:\n\n    Swedish massage. This is a gentle form of massage that uses long strokes, kneading, deep circular movements, vibration and tapping to help relax and energize you.\n    Deep massage. This massage technique uses slower, more-forceful strokes to target the deeper layers of muscle and connective tissue, commonly to help with muscle damage from injuries.\n    Sports massage. This is similar to Swedish massage, but it's geared toward people involved in sport activities to help prevent or treat injuries.\n    Trigger point massage. This massage focuses on areas of tight muscle fibers that can form in your muscles after injuries or overuse.\n\nBenefits of massage\n\nMassage is generally considered part of complementary and integrative medicine. It's increasingly being offered along with standard treatment for a wide range of medical conditions and situations.\n\nStudies of the benefits of massage demonstrate that it is an effective treatment for reducing stress, pain and muscle tension.\n\nWhile more research is needed to confirm the benefits of massage, some studies have found massage may also be helpful for:\n\n    Anxiety\n    Digestive disorders\n    Fibromyalgia\n    Headaches\n    Insomnia related to stress\n    Myofascial pain syndrome\n    Soft tissue strains or injuries\n    Sports injuries\n    Temporomandibular joint pain\n\nBeyond the benefits for specific conditions or diseases, some people enjoy massage because it often produces feelings of caring, comfort and connection.\n\nDespite its benefits, massage isn't meant as a replacement for regular medical care. Let your doctor know you're trying massage and be sure to follow any standard treatment plans you have.\nRisks of massage\n\n\n\nSome forms of massage can leave you feeling a bit sore the next day. But massage shouldn't ordinarily be painful or uncomfortable. If any part of your massage doesn't feel right or is painful, speak up right away. Most serious problems come from too much pressure during massage.\nWhat you can expect during a massage\n\nYou don't need any special preparation for massage. Before a massage therapy session starts, your massage therapist should ask you about any symptoms, your medical history and what you're hoping to get out of massage. Your massage therapist should explain the kind of massage and techniques he or she will use.\n\nIn a typical massage therapy session, you undress or wear loose-fitting clothing. Undress only to the point that you're comfortable. You generally lie on a table and cover yourself with a sheet. You can also have a massage while sitting in a chair, fully clothed. Your massage therapist should perform an evaluation through touch to locate painful or tense areas and to determine how much pressure to apply.\n\nDepending on preference, your massage therapist may use oil or lotion to reduce friction on your skin. Tell your massage therapist if you might be allergic to any ingredients.\n\nA massage session may last from 10 to 90 minutes, depending on the type of massage and how much time you have. No matter what kind of massage you choose, you should feel calm and relaxed during and after your massage.\n\nIf a massage therapist is pushing too hard, ask for lighter pressure. Occasionally you may have a sensitive spot in a muscle that feels like a knot. It's likely to be uncomfortable while your massage therapist works it out. But if it becomes painful, speak up.\nFinding a massage therapist\n\nAsk your doctor or someone else you trust for a recommendation. Most states regulate massage therapists through licensing, registration or certification requirements.\n\nDon't be afraid to ask a potential massage therapist such questions as:\n\n    Are you licensed, certified or registered?\n    What is your training and experience?\n    How many massage therapy sessions do you think I'll need?\n    What's the cost, and is it covered by health insurance?\n\nThe take-home message about massage\n\nBrush aside any thoughts that massage is only a feel-good way to indulge or pamper yourself. To the contrary, massage can be a powerful tool to help you take charge of your health and well-being, whether you have a specific health condition or are just looking for another stress reliever. You can even learn how to do self-massage or how to engage in massage with a partner at home. 
##                   Topic
## 1 chiropractic benefits
## 2 chiropractic benefits
## 3 chiropractic benefits
## 4 chiropractic benefits
## 5      massage benefits
## 6      massage benefits

We are to make our data table into a dplyr tibble.

text_df <- tibble(line=1:87, text=modalities1$Document,
                  Recommend=modalities1$Topic)
head(text_df)
## # A tibble: 6 x 3
##    line text                                                   Recommend        
##   <int> <fct>                                                  <fct>            
## 1     1 "Chiropractic adjustments and treatments serve the ne~ chiropractic ben~
## 2     2 "\nUnitedHealthcare Combats Opioid Crisis with Non-Op~ chiropractic ben~
## 3     3 " The Safety of Chiropractic Adjustments\nBy Lana Bar~ chiropractic ben~
## 4     4 "Advanced Chiropractic Relief: 8 Key Benefits of Chir~ chiropractic ben~
## 5     5 "Heading to the spa can be a pampering treat, but it ~ massage benefits 
## 6     6 "Massage: Get in touch with its many benefits\n\nMass~ massage benefits

Now for the word counts by line or in our case by review which is line.This uses the tidytext package to unnest the words as tokens from each review. We will use the ngrams method of tokenizing to get the sequential groups of threes for words used in combination. This will be very useful to us in predicting our ratings accurately. As we have seen that using a word like ‘like’ or ‘good’ has very similar word counts in ratings of 1 and ratings of 5 but not so much in the 2-4 range. This is because some of those likes are in ngrams of 2-3 with word pairings such as ‘don’t like’, ‘not as good’, etc.

text_df$text <- as.character(paste(text_df$text))

library(stopwords)
stop <- as.data.frame(stopwords())
colnames(stop) <- 'fillers'
# fills <- as.data.frame(c('of','the','a','an','in','by','it','as','or','go','goes','am','and','to'))
# colnames(fills) <- 'fillers'

text_df0 <- text_df %>% unnest_tokens(unigram,text,token='ngrams',n=1)

text_df01 <- anti_join(text_df0,stop, by=c("unigram"="fillers"))

We see from the above it basically goes along every string word and counts each white space to separate a character from a non-character and get each word, but it also does it for any three combinations, so that almost every word is part of the beginning of one trigram (as we set n to 3 for the number of ngrams, thus trigram), the middle of one trigram, or the end of a trigram. Look at ‘wonderful’ above and see what I am referring to.

text_df4 <- text_df01 %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
head(text_df4,30)
## # A tibble: 30 x 2
## # Groups:   unigram [30]
##    unigram      n
##    <chr>    <int>
##  1 massage    667
##  2 can        479
##  3 pain       347
##  4 therapy    328
##  5 health     298
##  6 help       263
##  7 cupping    261
##  8 physical   236
##  9 body       221
## 10 may        196
## # ... with 20 more rows

The above shows all documents bigram occurences of word pairs.

We want the recommended modality or health care option for each category counts of bigrams.

er <- subset(text_df01, text_df01$Recommend=='ER')
nonPro <- subset(text_df01, text_df01$Recommend=='Not Professional')
chiropractor <- subset(text_df01, text_df01$Recommend=='chiropractic benefits')
massage <- subset(text_df01, text_df01$Recommend=='massage benefits')
physicalTherapy <- subset(text_df01, text_df01$Recommend=='physical therapy benefits')
mental <- subset(text_df01, text_df01$Recommend=='mental health services benefits')
cupping <- subset(text_df01, text_df01$Recommend=='cupping benefits')
massageGun <- subset(text_df01, text_df01$Recommend=='massage gun benefits')
coldStone <- subset(text_df01, text_df01$Recommend=='cold stone benefits')

Group each category into bigram counts.

er2 <- er %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
er3 <- spread(er2,unigram,n)
freqER <- colSums(er3)

nonPro2 <- nonPro %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
nonPro3 <- spread(nonPro2,unigram,n)
freqNonPro <- colSums(nonPro3)

chiropractor2 <- chiropractor %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
chiropractor3 <- spread(chiropractor2,unigram,n)
freqChiropractor <- colSums(chiropractor3)

massage2 <- massage %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
massage3 <- spread(massage2,unigram,n)
freqMassage <- colSums(massage3)

physical2 <- physicalTherapy %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
physical3 <- spread(physical2,unigram,n)
freqPhysical <- colSums(physical3)

mental2 <- mental %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
mental3 <- spread(mental2,unigram,n)
freqMental <- colSums(mental3)

cupping2 <- cupping %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
cupping3 <- spread(cupping2,unigram,n)
freqCupping <- colSums(cupping3)

massageGun2 <- massageGun %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
massageGun3 <- spread(massageGun2,unigram,n)
freqMassageGun <- colSums(massageGun3)

coldStone2 <- coldStone %>% group_by(unigram) %>% count(unigram, sort=TRUE) 
coldStone3 <- spread(coldStone2,unigram,n)
freqColdStone <- colSums(coldStone3)
wordcloud(names(freqER), freqER,
          min.freq=10,colors=brewer.pal(3,'Dark2'))

The above word cloud is for Emergency Room services from qualified medical staff such as doctors and nurses.

wordcloud(names(freqNonPro), freqNonPro,
          min.freq=2,colors=brewer.pal(3,'Dark2'))

The word cloud above is for non-professional services. It was scrubbed from twitter using massage, but these tweets were not for professional massage services or requests.

wordcloud(names(freqChiropractor), freqChiropractor,
          min.freq=9,colors=brewer.pal(3,'Dark2'))

The word cloud above is for chiropractic services.

wordcloud(names(freqMassage), freqMassage, min.freq=9,colors=brewer.pal(3,'Dark2'))

The word cloud above is for massage therapy.

wordcloud(names(freqPhysical), freqPhysical,
          min.freq=10,colors=brewer.pal(3,'Dark2'))

The word cloud above is for physical therapy.

wordcloud(names(freqMental), freqMental,
          min.freq=10,colors=brewer.pal(3,'Dark2'))

The word cloud above is for mental health services.

wordcloud(names(freqCupping), freqCupping,
          min.freq=10,colors=brewer.pal(3,'Dark2'))

The word cloud above is for cupping therapy.

wordcloud(names(freqMassageGun), freqMassageGun,
          min.freq=10,colors=brewer.pal(3,'Dark2'))

The wordcloud above is for massage gun therapy.

wordcloud(names(freqColdStone), freqColdStone,
          min.freq=10,colors=brewer.pal(3,'Dark2'))

This word cloud above is for Cold stone therapy.


We saw how the count, tf-idf, and n-grams vectorized tokens for a dtm work. And found that the range of accuracy with our new added category for ER services, and the scrubbed risks and contraindications out of our health services’ documents, did score better than the last script with the added ‘Not Professional Services’ category and keeping the risks and contraindications within each document. Because that other previous model scored 62% on the testing set using only the count vectorization. And this script’s models ranged from 72-83% accuracy on the testing sets, with some questionable recommendations on the short user inputs. Both of the count and n-grams set to bigrams or 2 word adjacent pairings scored 72% on the testing sets, and the tf-idf scored 83% on the testing set. We saw in the first and second script that excluded the added ‘Not Professional Services’ category and included the risks and contraindications scored 92% and had better recommendations in the short user inputs as well.

Any of these models would be ok to use for fun, but they would still need to be improved by supplying better data in the first place, or by testing out other algorithms that could be time consuming such as the trees that random forest and rpart or gradient boosting trees.




Lets test out this type of ML on the previous dataset with out the non-professional and ER class but WITH the risks, side effects, and contraindications in each class, to see if these vectorization techniques improve that dataset. This is basically the 1st dataset to test on, benefitsContraindications.csv.

!@#\(% Section to start anew and test out the ML !@#\)%

library(reticulate)
conda_list(conda = "auto") 
##           name                                                  python
## 1    Anaconda2                     C:\\Users\\m\\Anaconda2\\python.exe
## 2    djangoenv    C:\\Users\\m\\Anaconda2\\envs\\djangoenv\\python.exe
## 3     python36     C:\\Users\\m\\Anaconda2\\envs\\python36\\python.exe
## 4     python37     C:\\Users\\m\\Anaconda2\\envs\\python37\\python.exe
## 5 r-reticulate C:\\Users\\m\\Anaconda2\\envs\\r-reticulate\\python.exe

Without having my python IDE, Anaconda, open in the console I want to use the python36 environment, all the environments in Anaconda for python are listed above.

use_condaenv(condaenv = "python36")
import pandas as pd 
import matplotlib.pyplot as plt 
from textblob import TextBlob 
import sklearn 
import numpy as np 
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer 
from sklearn.naive_bayes import MultinomialNB 
from sklearn.metrics import classification_report, f1_score, accuracy_score, confusion_matrix 

import re
import string
import nltk 

np.random.seed(47) 
set.seed(47)

The following data table will not show in your Rstudio environment, but python inside your python IDE will store the table.

modalities = pd.read_csv('benefitsContraindications.csv', encoding = 'unicode_escape') 
print(modalities.head())
##                                             Document  ... InternetSearch
## 0  Chiropractic adjustments and treatments serve ...  ...            NaN
## 1  \r\nUnitedHealthcare Combats Opioid Crisis wit...  ...            NaN
## 2   The Safety of Chiropractic Adjustments\r\nBy ...  ...            NaN
## 3  Advanced Chiropractic Relief: 8 Key Benefits o...  ...            NaN
## 4  Heading to the spa can be a pampering treat, b...  ...         google
## 
## [5 rows x 4 columns]
print(modalities.tail())
##                                              Document  ... InternetSearch
## 60  What is Hot & Cold Stone Therapy?\r\n\r\nHot &...  ...         google
## 61  \r\nBenefits of Hot Stone & Cold Stone Therapy...  ...         google
## 62  Benefits Of Hot & Cold Stone Massage\r\n\r\nBe...  ...         google
## 63  \r\nCool Down! Do you need a cold stone massag...  ...         google
## 64  \r\nCool Off Your Summer with Cold Stone Massa...  ...         google
## 
## [5 rows x 4 columns]
print(modalities.shape)
## (65, 4)
print(modalities.columns)
## Index(['Document', 'Source', 'Topic', 'InternetSearch'], dtype='object')
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text
modalities.tail()
##                                              Document  ... InternetSearch
## 60  What is Hot & Cold Stone Therapy?\r\n\r\nHot &...  ...         google
## 61  \r\nBenefits of Hot Stone & Cold Stone Therapy...  ...         google
## 62  Benefits Of Hot & Cold Stone Massage\r\n\r\nBe...  ...         google
## 63  \r\nCool Down! Do you need a cold stone massag...  ...         google
## 64  \r\nCool Off Your Summer with Cold Stone Massa...  ...         google
## 
## [5 rows x 4 columns]

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ... InternetSearch
## 44  What Is Cupping Therapy?\r\n\r\n    Cupping ty...  ...         google
## 33  \r\nChiropractic Care for Back Pain\r\nIn this...  ...         google
## 5   Massage: Get in touch with its many benefits\r...  ...         google
## 46  ll You Need To Know About Massage Gun\r\n31 Au...  ...         google
## 32  \r\nChiropractic Care for Back Pain\r\nIn this...  ...         google
## 
## [5 rows x 4 columns]
print(modalities.tail())
##                                              Document  ... InternetSearch
## 61  \r\nBenefits of Hot Stone & Cold Stone Therapy...  ...         google
## 8   BENEFITS OF MASSAGE\r\n\r\nYou know that post-...  ...         google
## 64  \r\nCool Off Your Summer with Cold Stone Massa...  ...         google
## 6   25 Reasons to Get a Massage\r\n\r\nNovember 5,...  ...         google
## 7   7 Benefits of Massage Therapy\r\n\r\nMassage t...  ...         google
## 
## [5 rows x 4 columns]
modalities.columns
## Index(['Document', 'Source', 'Topic', 'InternetSearch'], dtype='object')
modalities.groupby('Topic').describe()
##                                 Document         ... InternetSearch     
##                                    count unique  ...            top freq
## Topic                                            ...                    
## chiropractic benefits                  8      8  ...         google    4
## cold stone benefits                   10     10  ...         google   10
## cupping benefits                      10     10  ...         google   10
## massage benefits                      12     12  ...         google   12
## massage gun benefits                  10     10  ...         google   10
## mental health services benefits        6      6  ...         google    6
## physical therapy benefits              9      9  ...         google    9
## 
## [7 rows x 12 columns]
modalities['length'] = modalities['Document'].map(lambda text: len(text))
print(modalities.head())
##                                              Document  ... length
## 44  What Is Cupping Therapy?\r\n\r\n    Cupping ty...  ...   7723
## 33  \r\nChiropractic Care for Back Pain\r\nIn this...  ...   1478
## 5   Massage: Get in touch with its many benefits\r...  ...   5492
## 46  ll You Need To Know About Massage Gun\r\n31 Au...  ...   5521
## 32  \r\nChiropractic Care for Back Pain\r\nIn this...  ...   2762
## 
## [5 rows x 5 columns]
modalities.length.plot(bins=20, kind='hist')
plt.show()

modalities.length.describe()
## count       65.000000
## mean      4875.615385
## std       2983.255236
## min        382.000000
## 25%       2500.000000
## 50%       4188.000000
## 75%       6906.000000
## max      12846.000000
## Name: length, dtype: float64
print(list(modalities.Document[modalities.length > 3800].index))
## [44, 5, 46, 54, 29, 39, 38, 30, 3, 35, 40, 59, 25, 21, 27, 22, 42, 17, 2, 34, 28, 9, 53, 41, 1, 26, 50, 49, 45, 55, 58, 23, 16, 51, 7]
print(list(modalities.Topic[modalities.length > 3800]))
## ['cupping benefits', 'massage benefits', 'massage gun benefits', 'massage gun benefits', 'mental health services benefits', 'cupping benefits', 'cupping benefits', 'mental health services benefits', 'chiropractic benefits', 'cupping benefits', 'cupping benefits', 'cold stone benefits', 'mental health services benefits', 'physical therapy benefits', 'mental health services benefits', 'physical therapy benefits', 'cupping benefits', 'physical therapy benefits', 'chiropractic benefits', 'chiropractic benefits', 'mental health services benefits', 'massage benefits', 'massage gun benefits', 'cupping benefits', 'chiropractic benefits', 'mental health services benefits', 'massage gun benefits', 'massage gun benefits', 'massage gun benefits', 'cold stone benefits', 'cold stone benefits', 'physical therapy benefits', 'physical therapy benefits', 'massage gun benefits', 'massage benefits']
modalities.hist(column='length', by='Topic', bins=5)


plt.show()

def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 44    [What, Is, Cupping, Therapy, Cupping, types, T...
## 33    [Chiropractic, Care, for, Back, Pain, In, this...
## 5     [Massage, Get, in, touch, with, its, many, ben...
## 46    [ll, You, Need, To, Know, About, Massage, Gun,...
## 32    [Chiropractic, Care, for, Back, Pain, In, this...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 44    [cupping, therapy, cupping, type, treatment, c...
## 33    [chiropractic, care, back, pain, article, chir...
## 5     [massage, get, touch, many, benefit, massage, ...
## 46    [need, know, massage, gun, 31, august, 2019, 3...
## 32    [chiropractic, care, back, pain, article, chir...
## Name: Document, dtype: object
bow_transformer = CountVectorizer(analyzer=split_into_lemmas).fit(modalities['Document'])
print(len(bow_transformer.vocabulary_))
## 4769
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformer.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 76)    2
##   (0, 79)    1
##   (0, 96)    1
##   (0, 182)   2
##   (0, 207)   1
##   (0, 241)   1
##   (0, 244)   3
##   (0, 246)   1
##   (0, 247)   1
##   (0, 250)   2
##   (0, 284)   2
##   (0, 293)   1
##   (0, 312)   1
##   (0, 344)   1
##   (0, 345)   4
##   (0, 351)   1
##   (0, 372)   1
##   (0, 389)   1
##   (0, 406)   1
##   (0, 412)   1
##   (0, 427)   2
##   (0, 441)   7
##   :  :
##   (0, 4449)  1
##   (0, 4464)  2
##   (0, 4469)  1
##   (0, 4472)  1
##   (0, 4546)  3
##   (0, 4549)  1
##   (0, 4550)  2
##   (0, 4568)  1
##   (0, 4628)  2
##   (0, 4648)  4
##   (0, 4661)  2
##   (0, 4666)  1
##   (0, 4668)  2
##   (0, 4672)  1
##   (0, 4673)  1
##   (0, 4688)  1
##   (0, 4711)  2
##   (0, 4712)  1
##   (0, 4714)  1
##   (0, 4726)  2
##   (0, 4727)  1
##   (0, 4736)  1
##   (0, 4745)  1
##   (0, 4754)  1
##   (0, 4763)  1
modalities_bow = bow_transformer.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (65, 4769)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 16570
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 5.35%
modalities_bow
## <65x4769 sparse matrix of type '<class 'numpy.int64'>'
##  with 16570 stored elements in Compressed Sparse Row format>

Indexing is different in python compared to R. Python includes zero and when indicating a slice, the last value is ignored, so only up to the value. So it is used to slice, so that the next can start and include that number up to the empty slice which indicates the last value.


# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:52]
modalities_bow_test = modalities_bow[52:]
modalities_sentiment_train = modalities['Topic'][:52]
modalities_sentiment_test = modalities['Topic'][52:]

print(modalities_bow_train.shape)
## (52, 4769)
print(modalities_bow_test.shape)
## (13, 4769)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)
#print(predictions)


prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                   predictions                      Topic
## 49       massage gun benefits       massage gun benefits
## 45       massage gun benefits       massage gun benefits
## 55           massage benefits        cold stone benefits
## 62        cold stone benefits        cold stone benefits
## 58        cold stone benefits        cold stone benefits
## 23  physical therapy benefits  physical therapy benefits
## 16  physical therapy benefits  physical therapy benefits
## 51       massage gun benefits       massage gun benefits
## 61        cold stone benefits        cold stone benefits
## 8            massage benefits           massage benefits
## 64        cold stone benefits        cold stone benefits
## 6            massage benefits           massage benefits
## 7            massage benefits           massage benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.9230769230769231
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[4 1 0 0]
##  [0 3 0 0]
##  [0 0 3 0]
##  [0 0 0 2]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                            precision    recall  f1-score   support
## 
##       cold stone benefits       1.00      0.80      0.89         5
##          massage benefits       0.75      1.00      0.86         3
##      massage gun benefits       1.00      1.00      1.00         3
## physical therapy benefits       1.00      1.00      1.00         2
## 
##                  accuracy                           0.92        13
##                 macro avg       0.94      0.95      0.94        13
##              weighted avg       0.94      0.92      0.92        13

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['chiropractic benefits', 'cold stone benefits', 'cupping benefits',
##        'massage benefits', 'massage gun benefits',
##        'mental health services benefits', 'physical therapy benefits'],
##       dtype=object)

The ‘Not Professional’ class is not getting sorted alphabetically with the others nor is the ER class. This may be because of the uppercase priority in sorting that effects the order of probability readings.


def predict_modality(new_review): 
    new_sample = bow_transformer.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    # if (pr[0][0] == max(pr[0])):
    #     print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    # elif (pr[0][1] == max(pr[0])):
    #     print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    if (pr[0][0] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][0]*100,'%')
        
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][2]*100,'%')
   
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][3]*100,'%')
    
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][4]*100,'%')
    
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][5]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][6]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.36 0.07 0.04 0.5  0.02 0.01 0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  50.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.02 0.78 0.17 0.02 0.01 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  78.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.06 0.07 0.14 0.27 0.27 0.08 0.11]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  27.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.36 0.   0.06 0.29 0.09 0.   0.19]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is chiropractic therapy for this recommendation with  36.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.36 0.07 0.11 0.42 0.01 0.01 0.02]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  42.0 %
## -----------------------------------------

The above should be under contraindications for massage, but we didn’t move that far. Those are listings of contraindications for massage in mentioning the dizzy, nausious, and breathing ragged. But we didn’t add in any medical professional services categories to our data to classify. We should do that later.

predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.35 0.   0.05 0.46 0.03 0.   0.11]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  46.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.1  0.02 0.33 0.02 0.04 0.44 0.05]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is mental health therapy for this recommendation with  44.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0. 0. 0. 1. 0. 0. 0.]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  100.0 %
## -----------------------------------------


from sklearn.feature_extraction.text import TfidfVectorizer

bow_transformerTFIDF = TfidfVectorizer(analyzer=split_into_lemmas).fit(modalities['Document'])
print(len(bow_transformerTFIDF.vocabulary_))
## 4769
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerTFIDF.transform([modality4])
print(bow4)
##   (0, 4763)  0.03514532568027957
##   (0, 4754)  0.02535355686279223
##   (0, 4745)  0.016403044219016696
##   (0, 4736)  0.03514532568027957
##   (0, 4727)  0.02535355686279223
##   (0, 4726)  0.03509783454360583
##   (0, 4714)  0.018418272235963117
##   (0, 4712)  0.031976154255200576
##   (0, 4711)  0.021619317861434683
##   (0, 4688)  0.03514532568027957
##   (0, 4673)  0.018892122674076802
##   (0, 4672)  0.031976154255200576
##   (0, 4668)  0.027957660711592672
##   (0, 4666)  0.03514532568027957
##   (0, 4661)  0.037784245348153604
##   (0, 4648)  0.059209370936962956
##   (0, 4628)  0.033533302204624624
##   (0, 4568)  0.031976154255200576
##   (0, 4550)  0.03879312938239452
##   (0, 4549)  0.012773967298788914
##   (0, 4546)  0.039001613701686574
##   (0, 4472)  0.03514532568027957
##   (0, 4469)  0.02114068558439873
##   (0, 4464)  0.03509783454360583
##   (0, 4449)  0.02430985700947772
##   :  :
##   (0, 441)   0.08076086596595539
##   (0, 427)   0.04513147223255251
##   (0, 412)   0.02535355686279223
##   (0, 406)   0.01605560308803705
##   (0, 389)   0.03514532568027957
##   (0, 372)   0.026558419919799653
##   (0, 351)   0.018418272235963117
##   (0, 345)   0.0393254659019328
##   (0, 344)   0.03514532568027957
##   (0, 312)   0.029727591344878648
##   (0, 293)   0.02114068558439873
##   (0, 284)   0.055966940903354356
##   (0, 250)   0.059455182689757295
##   (0, 247)   0.029727591344878648
##   (0, 246)   0.031976154255200576
##   (0, 244)   0.06546233566325285
##   (0, 241)   0.023389248494720655
##   (0, 207)   0.017148001780875333
##   (0, 182)   0.03879312938239452
##   (0, 96)    0.029727591344878648
##   (0, 79)    0.022565736116276255
##   (0, 76)    0.05070711372558446
##   (0, 7) 0.11736655771618619
##   (0, 5) 0.04513147223255251
##   (0, 3) 0.053116839839599306
modalities_bow = bow_transformerTFIDF.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (65, 4769)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 16570
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 5.35%
modalities_bow
## <65x4769 sparse matrix of type '<class 'numpy.float64'>'
##  with 16570 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:52]
modalities_bow_test = modalities_bow[52:]
modalities_sentiment_train = modalities['Topic'][:52]
modalities_sentiment_test = modalities['Topic'][52:]

print(modalities_bow_train.shape)
## (52, 4769)
print(modalities_bow_test.shape)
## (13, 4769)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)
# print(predictions)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']

prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                   predictions                      Topic
## 49       massage gun benefits       massage gun benefits
## 45       massage gun benefits       massage gun benefits
## 55           massage benefits        cold stone benefits
## 62        cold stone benefits        cold stone benefits
## 58        cold stone benefits        cold stone benefits
## 23  physical therapy benefits  physical therapy benefits
## 16  physical therapy benefits  physical therapy benefits
## 51       massage gun benefits       massage gun benefits
## 61        cold stone benefits        cold stone benefits
## 8            massage benefits           massage benefits
## 64        cold stone benefits        cold stone benefits
## 6            massage benefits           massage benefits
## 7            massage benefits           massage benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.9230769230769231
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[4 1 0 0]
##  [0 3 0 0]
##  [0 0 3 0]
##  [0 0 0 2]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                            precision    recall  f1-score   support
## 
##       cold stone benefits       1.00      0.80      0.89         5
##          massage benefits       0.75      1.00      0.86         3
##      massage gun benefits       1.00      1.00      1.00         3
## physical therapy benefits       1.00      1.00      1.00         2
## 
##                  accuracy                           0.92        13
##                 macro avg       0.94      0.95      0.94        13
##              weighted avg       0.94      0.92      0.92        13

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['chiropractic benefits', 'cold stone benefits', 'cupping benefits',
##        'massage benefits', 'massage gun benefits',
##        'mental health services benefits', 'physical therapy benefits'],
##       dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerTFIDF.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    # if (pr[0][0] == max(pr[0])):
    #     print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    # elif (pr[0][1] == max(pr[0])):
    #     print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    if (pr[0][0] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][0]*100,'%')
        
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][2]*100,'%')
   
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][3]*100,'%')
    
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][4]*100,'%')
    
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][5]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][6]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.17 0.09 0.18 0.2  0.13 0.11 0.13]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  20.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.14 0.16 0.19 0.17 0.12 0.1  0.11]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cupping therapy for this recommendation with  19.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.15 0.09 0.19 0.18 0.14 0.11 0.14]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cupping therapy for this recommendation with  19.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.16 0.09 0.19 0.18 0.13 0.1  0.15]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cupping therapy for this recommendation with  19.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.16 0.09 0.19 0.19 0.13 0.11 0.13]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cupping therapy for this recommendation with  19.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.17 0.08 0.18 0.19 0.12 0.09 0.17]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  19.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.15 0.09 0.21 0.16 0.13 0.12 0.13]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cupping therapy for this recommendation with  21.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.15 0.09 0.18 0.22 0.14 0.1  0.12]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  22.0 %
## -----------------------------------------

The TF-IDF vectorized dtm performed worse in recommending an accurate class for the testing set and the short user inputs. Lets try out the N-grams and see if it is better.


N-gram Vectorization

modalities = pd.read_csv('benefitsContraindications.csv', encoding = 'unicode_escape') 
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ... InternetSearch
## 62  Benefits Of Hot & Cold Stone Massage\r\n\r\nBe...  ...         google
## 0   Chiropractic adjustments and treatments serve ...  ...            NaN
## 4   Heading to the spa can be a pampering treat, b...  ...         google
## 55  Cold Stone Therapy for Migraine Headaches\r\n\...  ...         google
## 3   Advanced Chiropractic Relief: 8 Key Benefits o...  ...            NaN
## 
## [5 rows x 4 columns]
print(modalities.tail())
##                                              Document  ... InternetSearch
## 25  \r\nThe Challenges and Benefits of Treatment f...  ...         google
## 56  Cold Stone Massage is Beneficial, Too - by adm...  ...         google
## 15  Top 5 Health Benefits of Regular Massage Thera...  ...         google
## 48  re Massage Guns Worth It? Here's What An Exper...  ...         google
## 31  \r\n21 Benefits of Chiropractic Adjustments\r\...  ...         google
## 
## [5 rows x 4 columns]
def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 62    [Benefits, Of, Hot, Cold, Stone, Massage, Bene...
## 0     [Chiropractic, adjustments, and, treatments, s...
## 4     [Heading, to, the, spa, can, be, a, pampering,...
## 55    [Cold, Stone, Therapy, for, Migraine, Headache...
## 3     [Advanced, Chiropractic, Relief, 8, Key, Benef...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 62    [benefit, hot, cold, stone, massage, benefit, ...
## 0     [chiropractic, adjustment, treatment, serve, n...
## 4     [heading, spa, pampering, treat, also, huge, b...
## 55    [cold, stone, therapy, migraine, headache, kel...
## 3     [advanced, chiropractic, relief, 8, key, benef...
## Name: Document, dtype: object
bow_transformerNgrams = CountVectorizer(analyzer=split_into_lemmas,ngram_range=(2,2)).fit(modalities['Document'])
          
print(len(bow_transformerNgrams.vocabulary_))
## 4769
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerNgrams.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 76)    2
##   (0, 79)    1
##   (0, 96)    1
##   (0, 182)   2
##   (0, 207)   1
##   (0, 241)   1
##   (0, 244)   3
##   (0, 246)   1
##   (0, 247)   1
##   (0, 250)   2
##   (0, 284)   2
##   (0, 293)   1
##   (0, 312)   1
##   (0, 344)   1
##   (0, 345)   4
##   (0, 351)   1
##   (0, 372)   1
##   (0, 389)   1
##   (0, 406)   1
##   (0, 412)   1
##   (0, 427)   2
##   (0, 441)   7
##   :  :
##   (0, 4449)  1
##   (0, 4464)  2
##   (0, 4469)  1
##   (0, 4472)  1
##   (0, 4546)  3
##   (0, 4549)  1
##   (0, 4550)  2
##   (0, 4568)  1
##   (0, 4628)  2
##   (0, 4648)  4
##   (0, 4661)  2
##   (0, 4666)  1
##   (0, 4668)  2
##   (0, 4672)  1
##   (0, 4673)  1
##   (0, 4688)  1
##   (0, 4711)  2
##   (0, 4712)  1
##   (0, 4714)  1
##   (0, 4726)  2
##   (0, 4727)  1
##   (0, 4736)  1
##   (0, 4745)  1
##   (0, 4754)  1
##   (0, 4763)  1
modalities_bow = bow_transformerNgrams.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (65, 4769)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 16570
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 5.35%
modalities_bow
## <65x4769 sparse matrix of type '<class 'numpy.int64'>'
##  with 16570 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:52]
modalities_bow_test = modalities_bow[52:]
modalities_sentiment_train = modalities['Topic'][:52]
modalities_sentiment_test = modalities['Topic'][52:]

print(modalities_bow_train.shape)
## (52, 4769)
print(modalities_bow_test.shape)
## (13, 4769)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                         predictions                            Topic
## 50             massage gun benefits             massage gun benefits
## 21        physical therapy benefits        physical therapy benefits
## 60              cold stone benefits              cold stone benefits
## 59              cold stone benefits              cold stone benefits
## 57              cold stone benefits              cold stone benefits
## 6                  massage benefits                 massage benefits
## 64              cold stone benefits              cold stone benefits
## 26  mental health services benefits  mental health services benefits
## 25  mental health services benefits  mental health services benefits
## 56              cold stone benefits              cold stone benefits
## 15                 massage benefits                 massage benefits
## 48             massage gun benefits             massage gun benefits
## 31            chiropractic benefits            chiropractic benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 1.0
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[1 0 0 0 0 0]
##  [0 5 0 0 0 0]
##  [0 0 2 0 0 0]
##  [0 0 0 2 0 0]
##  [0 0 0 0 2 0]
##  [0 0 0 0 0 1]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                                  precision    recall  f1-score   support
## 
##           chiropractic benefits       1.00      1.00      1.00         1
##             cold stone benefits       1.00      1.00      1.00         5
##                massage benefits       1.00      1.00      1.00         2
##            massage gun benefits       1.00      1.00      1.00         2
## mental health services benefits       1.00      1.00      1.00         2
##       physical therapy benefits       1.00      1.00      1.00         1
## 
##                        accuracy                           1.00        13
##                       macro avg       1.00      1.00      1.00        13
##                    weighted avg       1.00      1.00      1.00        13

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['chiropractic benefits', 'cold stone benefits', 'cupping benefits',
##        'massage benefits', 'massage gun benefits',
##        'mental health services benefits', 'physical therapy benefits'],
##       dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerNgrams.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    # if (pr[0][0] == max(pr[0])):
    #     print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    # elif (pr[0][1] == max(pr[0])):
    #     print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    if (pr[0][0] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][0]*100,'%')
        
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][2]*100,'%')
   
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][3]*100,'%')
    
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][4]*100,'%')
    
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][5]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][6]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.12 0.11 0.03 0.7  0.03 0.   0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  70.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.02 0.66 0.24 0.04 0.04 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  66.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.03 0.03 0.08 0.27 0.47 0.01 0.1 ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  47.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.31 0.02 0.05 0.44 0.05 0.   0.13]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  44.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.28 0.32 0.09 0.29 0.02 0.   0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  32.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.23 0.   0.05 0.49 0.1  0.   0.13]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  49.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.09 0.07 0.63 0.03 0.09 0.04 0.05]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cupping therapy for this recommendation with  63.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.   0.   0.   0.82 0.18 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  82.0 %
## -----------------------------------------

Lets use a trigram this time. There seems to be a buch of words associated with other words, like ‘quality of life,’ ‘muscle strength improved,’ ‘less stressed life,’ etc.

N-gram Vectorization: (Bi-Tri-Quad)gram

modalities = pd.read_csv('benefitsContraindications.csv', encoding = 'unicode_escape') 
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ... InternetSearch
## 36  \r\nCupping Therapy\r\nIn this Article\r\n\r\n...  ...         google
## 47  \r\nBenefits of Vibration and Percussion Thera...  ...         google
## 29  \r\nFinding Help: When to Get It and Where to ...  ...         google
## 13  \r\nThai Massage\r\n\r\nDuring a Thai massage,...  ...         google
## 2    The Safety of Chiropractic Adjustments\r\nBy ...  ...            NaN
## 
## [5 rows x 4 columns]
print(modalities.tail())
##                                              Document  ... InternetSearch
## 14  What Are the Health Benefits of Massage?\r\n\r...  ...         google
## 46  ll You Need To Know About Massage Gun\r\n31 Au...  ...         google
## 49  \r\nEverything You Need To Know About Massage ...  ...         google
## 34  Should I See a Chiropractor?\r\nTreatment prov...  ...         google
## 8   BENEFITS OF MASSAGE\r\n\r\nYou know that post-...  ...         google
## 
## [5 rows x 4 columns]
def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 36    [Cupping, Therapy, In, this, Article, Types, W...
## 47    [Benefits, of, Vibration, and, Percussion, The...
## 29    [Finding, Help, When, to, Get, It, and, Where,...
## 13    [Thai, Massage, During, a, Thai, massage, the,...
## 2     [The, Safety, of, Chiropractic, Adjustments, B...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 36    [cupping, therapy, article, type, research, sh...
## 47    [benefit, vibration, percussion, therapy, vibr...
## 29    [finding, help, get, go, finding, help, get, g...
## 13    [thai, massage, thai, massage, therapist, us, ...
## 2     [safety, chiropractic, adjustment, lana, barhu...
## Name: Document, dtype: object
bow_transformerNgrams = CountVectorizer(analyzer=split_into_lemmas,ngram_range=(2,4)).fit(modalities['Document'])
          
print(len(bow_transformerNgrams.vocabulary_))
## 4769
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerNgrams.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 76)    2
##   (0, 79)    1
##   (0, 96)    1
##   (0, 182)   2
##   (0, 207)   1
##   (0, 241)   1
##   (0, 244)   3
##   (0, 246)   1
##   (0, 247)   1
##   (0, 250)   2
##   (0, 284)   2
##   (0, 293)   1
##   (0, 312)   1
##   (0, 344)   1
##   (0, 345)   4
##   (0, 351)   1
##   (0, 372)   1
##   (0, 389)   1
##   (0, 406)   1
##   (0, 412)   1
##   (0, 427)   2
##   (0, 441)   7
##   :  :
##   (0, 4449)  1
##   (0, 4464)  2
##   (0, 4469)  1
##   (0, 4472)  1
##   (0, 4546)  3
##   (0, 4549)  1
##   (0, 4550)  2
##   (0, 4568)  1
##   (0, 4628)  2
##   (0, 4648)  4
##   (0, 4661)  2
##   (0, 4666)  1
##   (0, 4668)  2
##   (0, 4672)  1
##   (0, 4673)  1
##   (0, 4688)  1
##   (0, 4711)  2
##   (0, 4712)  1
##   (0, 4714)  1
##   (0, 4726)  2
##   (0, 4727)  1
##   (0, 4736)  1
##   (0, 4745)  1
##   (0, 4754)  1
##   (0, 4763)  1
modalities_bow = bow_transformerNgrams.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (65, 4769)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 16570
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 5.35%
modalities_bow
## <65x4769 sparse matrix of type '<class 'numpy.int64'>'
##  with 16570 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:52]
modalities_bow_test = modalities_bow[52:]
modalities_sentiment_train = modalities['Topic'][:52]
modalities_sentiment_test = modalities['Topic'][52:]

print(modalities_bow_train.shape)
## (52, 4769)
print(modalities_bow_test.shape)
## (13, 4769)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                         predictions                            Topic
## 63              cold stone benefits              cold stone benefits
## 44                 cupping benefits                 cupping benefits
## 11                 massage benefits                 massage benefits
## 30  mental health services benefits  mental health services benefits
## 62              cold stone benefits              cold stone benefits
## 33            chiropractic benefits            chiropractic benefits
## 57              cold stone benefits              cold stone benefits
## 50             massage gun benefits             massage gun benefits
## 14                 massage benefits                 massage benefits
## 46             massage gun benefits             massage gun benefits
## 49             massage gun benefits             massage gun benefits
## 34            chiropractic benefits            chiropractic benefits
## 8                  massage benefits                 massage benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 1.0
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[2 0 0 0 0 0]
##  [0 3 0 0 0 0]
##  [0 0 1 0 0 0]
##  [0 0 0 3 0 0]
##  [0 0 0 0 3 0]
##  [0 0 0 0 0 1]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                                  precision    recall  f1-score   support
## 
##           chiropractic benefits       1.00      1.00      1.00         2
##             cold stone benefits       1.00      1.00      1.00         3
##                cupping benefits       1.00      1.00      1.00         1
##                massage benefits       1.00      1.00      1.00         3
##            massage gun benefits       1.00      1.00      1.00         3
## mental health services benefits       1.00      1.00      1.00         1
## 
##                        accuracy                           1.00        13
##                       macro avg       1.00      1.00      1.00        13
##                    weighted avg       1.00      1.00      1.00        13

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['chiropractic benefits', 'cold stone benefits', 'cupping benefits',
##        'massage benefits', 'massage gun benefits',
##        'mental health services benefits', 'physical therapy benefits'],
##       dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerNgrams.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    # if (pr[0][0] == max(pr[0])):
    #     print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    # elif (pr[0][1] == max(pr[0])):
    #     print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    if (pr[0][0] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][0]*100,'%')
        
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][2]*100,'%')
   
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][3]*100,'%')
    
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][4]*100,'%')
    
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][5]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][6]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.21 0.17 0.02 0.57 0.02 0.01 0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  56.99999999999999 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.02 0.78 0.14 0.03 0.03 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  78.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.04 0.06 0.05 0.27 0.43 0.03 0.12]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  43.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.15 0.02 0.07 0.57 0.05 0.   0.14]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  56.99999999999999 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.47 0.23 0.05 0.2  0.01 0.01 0.02]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is chiropractic therapy for this recommendation with  47.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.3  0.   0.09 0.39 0.04 0.   0.18]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  39.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.08 0.21 0.22 0.01 0.02 0.43 0.03]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is mental health therapy for this recommendation with  43.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.   0.   0.   0.99 0.01 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  99.0 %
## -----------------------------------------

N-gram Vectorization-(bi-tri-quad)gram with two additional categories-risks scrubbed

modalities = pd.read_csv('benefitsContraindications3.csv', encoding = 'unicode_escape') 
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ... risksAdverseEffects
## 81  Signs of an Emergency\r\n\r\nHow quickly do yo...  ...                 NaN
## 49  \r\nEverything You Need To Know About Massage ...  ...                 NaN
## 27  The Benefits of Mental Health According to Sci...  ...                 NaN
## 86  Is It an Emergency?\r\n\r\nConditions we treat...  ...                 NaN
## 35  Home ? The Many Benefits of Chinese Cupping\r\...  ...                 NaN
## 
## [5 rows x 6 columns]
print(modalities.tail())
##                                              Document  ... risksAdverseEffects
## 59  A Guide to Cold Stone Massage\r\n\r\nWhy in th...  ...                 NaN
## 41  \r\n    Benefit\r\n    Possible Side Effects\r...  ...                 NaN
## 11  \r\nMassage Therapy Styles and Health Benefits...  ...                 NaN
## 28  Mental health providers: Tips on finding one\r...  ...                 NaN
## 38  Cupping Therapy\r\nPrivacy & Trust Info\r\nCor...  ...                 NaN
## 
## [5 rows x 6 columns]
def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 81    [Signs, of, an, Emergency, How, quickly, do, y...
## 49    [Everything, You, Need, To, Know, About, Massa...
## 27    [The, Benefits, of, Mental, Health, According,...
## 86    [Is, It, an, Emergency, Conditions, we, treat,...
## 35    [Home, The, Many, Benefits, of, Chinese, Cuppi...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 81    [sign, emergency, quickly, need, care, person,...
## 49    [everything, need, know, massage, gun, get, re...
## 27    [benefit, mental, health, according, science, ...
## 86    [emergency, condition, treat, dignity, health,...
## 35    [home, many, benefit, chinese, cupping, many, ...
## Name: Document, dtype: object
bow_transformerNgrams = CountVectorizer(analyzer=split_into_lemmas,ngram_range=(2,4)).fit(modalities['Document'])
          
print(len(bow_transformerNgrams.vocabulary_))
## 5102
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerNgrams.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 75)    2
##   (0, 78)    1
##   (0, 94)    1
##   (0, 184)   2
##   (0, 209)   1
##   (0, 242)   1
##   (0, 245)   3
##   (0, 247)   1
##   (0, 248)   1
##   (0, 251)   2
##   (0, 290)   2
##   (0, 298)   1
##   (0, 319)   1
##   (0, 354)   1
##   (0, 355)   4
##   (0, 361)   1
##   (0, 384)   1
##   (0, 400)   1
##   (0, 417)   1
##   (0, 423)   1
##   (0, 437)   2
##   (0, 451)   7
##   :  :
##   (0, 4721)  1
##   (0, 4735)  2
##   (0, 4740)  1
##   (0, 4744)  1
##   (0, 4824)  3
##   (0, 4827)  1
##   (0, 4828)  2
##   (0, 4847)  1
##   (0, 4914)  2
##   (0, 4935)  4
##   (0, 4949)  2
##   (0, 4955)  1
##   (0, 4958)  2
##   (0, 4962)  1
##   (0, 4963)  1
##   (0, 4985)  1
##   (0, 5013)  2
##   (0, 5014)  1
##   (0, 5016)  1
##   (0, 5028)  2
##   (0, 5029)  1
##   (0, 5038)  1
##   (0, 5047)  1
##   (0, 5058)  1
##   (0, 5070)  1
modalities_bow = bow_transformerNgrams.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (87, 5102)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 17813
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 4.01%
modalities_bow
## <87x5102 sparse matrix of type '<class 'numpy.int64'>'
##  with 17813 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:70]
modalities_bow_test = modalities_bow[70:]
modalities_sentiment_train = modalities['Topic'][:70]
modalities_sentiment_test = modalities['Topic'][70:]

print(modalities_bow_train.shape)
## (70, 5102)
print(modalities_bow_test.shape)
## (17, 5102)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                         predictions                            Topic
## 83                               ER                               ER
## 85                               ER                               ER
## 1             chiropractic benefits            chiropractic benefits
## 36                 cupping benefits                 cupping benefits
## 66                 Not Professional                 Not Professional
## 46             massage gun benefits             massage gun benefits
## 70                 massage benefits                 Not Professional
## 61              cold stone benefits              cold stone benefits
## 67                 Not Professional                 Not Professional
## 77             massage gun benefits                 Not Professional
## 50             massage gun benefits             massage gun benefits
## 31            chiropractic benefits            chiropractic benefits
## 59              cold stone benefits              cold stone benefits
## 41                 cupping benefits                 cupping benefits
## 11                 massage benefits                 massage benefits
## 28  mental health services benefits  mental health services benefits
## 38                 cupping benefits                 cupping benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.8823529411764706
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[2 0 0 0 0 0 0 0]
##  [0 2 0 0 0 1 1 0]
##  [0 0 2 0 0 0 0 0]
##  [0 0 0 2 0 0 0 0]
##  [0 0 0 0 3 0 0 0]
##  [0 0 0 0 0 1 0 0]
##  [0 0 0 0 0 0 2 0]
##  [0 0 0 0 0 0 0 1]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                                  precision    recall  f1-score   support
## 
##                              ER       1.00      1.00      1.00         2
##                Not Professional       1.00      0.50      0.67         4
##           chiropractic benefits       1.00      1.00      1.00         2
##             cold stone benefits       1.00      1.00      1.00         2
##                cupping benefits       1.00      1.00      1.00         3
##                massage benefits       0.50      1.00      0.67         1
##            massage gun benefits       0.67      1.00      0.80         2
## mental health services benefits       1.00      1.00      1.00         1
## 
##                        accuracy                           0.88        17
##                       macro avg       0.90      0.94      0.89        17
##                    weighted avg       0.93      0.88      0.88        17

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['ER', 'Not Professional', 'chiropractic benefits',
##        'cold stone benefits', 'cupping benefits', 'massage benefits',
##        'massage gun benefits', 'mental health services benefits',
##        'physical therapy benefits'], dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerNgrams.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    if (pr[0][0] == max(pr[0])):
        print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][2]*100,'%')
        
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][3]*100,'%')
        
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][4]*100,'%')
   
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][5]*100,'%')
    
    elif (pr[0][6] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][6]*100,'%')
    
    elif (pr[0][7] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][7]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][8]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.   0.01 0.08 0.15 0.01 0.71 0.02 0.01 0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  71.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.   0.   0.01 0.91 0.03 0.02 0.02 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  91.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.   0.05 0.02 0.09 0.05 0.24 0.43 0.04 0.08]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  43.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.3  0.   0.11 0.02 0.01 0.4  0.07 0.   0.08]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  40.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.18 0.02 0.25 0.18 0.02 0.31 0.02 0.   0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  31.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.   0.   0.26 0.01 0.02 0.49 0.05 0.   0.18]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  49.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.03 0.11 0.05 0.11 0.2  0.01 0.02 0.44 0.03]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is mental health therapy for this recommendation with  44.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.   0.   0.   0.   0.   0.86 0.14 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  86.0 %
## -----------------------------------------

N-gram Vectorization-(bi-tri-quad-quint-sext-sept-oct)gram with two additional categories-risks scrubbed

modalities = pd.read_csv('benefitsContraindications3.csv', encoding = 'unicode_escape') 
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ... risksAdverseEffects
## 28  Mental health providers: Tips on finding one\r...  ...                 NaN
## 22   How Physical Therapy Can Help Your Recovery\r...  ...                 NaN
## 65                        Massage Parlor got me right  ...                 NaN
## 15  Top 5 Health Benefits of Regular Massage Thera...  ...                 NaN
## 82  General guidelines - When to visit an emergenc...  ...                 NaN
## 
## [5 rows x 6 columns]
print(modalities.tail())
##                                              Document  ... risksAdverseEffects
## 84  How to Know If You Need to Go to the E.R. With...  ...                 NaN
## 36  \r\nCupping Therapy\r\nIn this Article\r\n\r\n...  ...                 NaN
## 21  The Benefits of Physical Therapy\r\nPosted: 10...  ...                 NaN
## 49  \r\nEverything You Need To Know About Massage ...  ...                 NaN
## 62  Benefits Of Hot & Cold Stone Massage\r\n\r\nBe...  ...                 NaN
## 
## [5 rows x 6 columns]
def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 28    [Mental, health, providers, Tips, on, finding,...
## 22    [How, Physical, Therapy, Can, Help, Your, Reco...
## 65                    [Massage, Parlor, got, me, right]
## 15    [Top, 5, Health, Benefits, of, Regular, Massag...
## 82    [General, guidelines, When, to, visit, an, eme...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 28    [mental, health, provider, tip, finding, one, ...
## 22    [physical, therapy, help, recovery, jonathan, ...
## 65                        [massage, parlor, got, right]
## 15    [top, 5, health, benefit, regular, massage, th...
## 82    [general, guideline, visit, emergency, room, c...
## Name: Document, dtype: object
bow_transformerNgrams = CountVectorizer(analyzer=split_into_lemmas,ngram_range=(2,8)).fit(modalities['Document'])
          
print(len(bow_transformerNgrams.vocabulary_))
## 5102
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerNgrams.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 75)    2
##   (0, 78)    1
##   (0, 94)    1
##   (0, 184)   2
##   (0, 209)   1
##   (0, 242)   1
##   (0, 245)   3
##   (0, 247)   1
##   (0, 248)   1
##   (0, 251)   2
##   (0, 290)   2
##   (0, 298)   1
##   (0, 319)   1
##   (0, 354)   1
##   (0, 355)   4
##   (0, 361)   1
##   (0, 384)   1
##   (0, 400)   1
##   (0, 417)   1
##   (0, 423)   1
##   (0, 437)   2
##   (0, 451)   7
##   :  :
##   (0, 4721)  1
##   (0, 4735)  2
##   (0, 4740)  1
##   (0, 4744)  1
##   (0, 4824)  3
##   (0, 4827)  1
##   (0, 4828)  2
##   (0, 4847)  1
##   (0, 4914)  2
##   (0, 4935)  4
##   (0, 4949)  2
##   (0, 4955)  1
##   (0, 4958)  2
##   (0, 4962)  1
##   (0, 4963)  1
##   (0, 4985)  1
##   (0, 5013)  2
##   (0, 5014)  1
##   (0, 5016)  1
##   (0, 5028)  2
##   (0, 5029)  1
##   (0, 5038)  1
##   (0, 5047)  1
##   (0, 5058)  1
##   (0, 5070)  1
modalities_bow = bow_transformerNgrams.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (87, 5102)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 17813
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 4.01%
modalities_bow
## <87x5102 sparse matrix of type '<class 'numpy.int64'>'
##  with 17813 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:70]
modalities_bow_test = modalities_bow[70:]
modalities_sentiment_train = modalities['Topic'][:70]
modalities_sentiment_test = modalities['Topic'][70:]

print(modalities_bow_train.shape)
## (70, 5102)
print(modalities_bow_test.shape)
## (17, 5102)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                         predictions                            Topic
## 55                 massage benefits              cold stone benefits
## 58              cold stone benefits              cold stone benefits
## 18        physical therapy benefits        physical therapy benefits
## 25  mental health services benefits  mental health services benefits
## 76                 cupping benefits                 Not Professional
## 42                 cupping benefits                 cupping benefits
## 73             massage gun benefits                 Not Professional
## 13                 massage benefits                 massage benefits
## 47             massage gun benefits             massage gun benefits
## 66                 Not Professional                 Not Professional
## 86                               ER                               ER
## 1             chiropractic benefits            chiropractic benefits
## 84                               ER                               ER
## 36                 cupping benefits                 cupping benefits
## 21        physical therapy benefits        physical therapy benefits
## 49             massage gun benefits             massage gun benefits
## 62              cold stone benefits              cold stone benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.8235294117647058
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[2 0 0 0 0 0 0 0 0]
##  [0 1 0 0 1 0 1 0 0]
##  [0 0 1 0 0 0 0 0 0]
##  [0 0 0 2 0 1 0 0 0]
##  [0 0 0 0 2 0 0 0 0]
##  [0 0 0 0 0 1 0 0 0]
##  [0 0 0 0 0 0 2 0 0]
##  [0 0 0 0 0 0 0 1 0]
##  [0 0 0 0 0 0 0 0 2]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                                  precision    recall  f1-score   support
## 
##                              ER       1.00      1.00      1.00         2
##                Not Professional       1.00      0.33      0.50         3
##           chiropractic benefits       1.00      1.00      1.00         1
##             cold stone benefits       1.00      0.67      0.80         3
##                cupping benefits       0.67      1.00      0.80         2
##                massage benefits       0.50      1.00      0.67         1
##            massage gun benefits       0.67      1.00      0.80         2
## mental health services benefits       1.00      1.00      1.00         1
##       physical therapy benefits       1.00      1.00      1.00         2
## 
##                        accuracy                           0.82        17
##                       macro avg       0.87      0.89      0.84        17
##                    weighted avg       0.89      0.82      0.81        17

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['ER', 'Not Professional', 'chiropractic benefits',
##        'cold stone benefits', 'cupping benefits', 'massage benefits',
##        'massage gun benefits', 'mental health services benefits',
##        'physical therapy benefits'], dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerNgrams.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    if (pr[0][0] == max(pr[0])):
        print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][2]*100,'%')
        
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][3]*100,'%')
        
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][4]*100,'%')
   
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][5]*100,'%')
    
    elif (pr[0][6] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][6]*100,'%')
    
    elif (pr[0][7] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][7]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][8]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.   0.02 0.21 0.06 0.02 0.66 0.02 0.01 0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  66.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.   0.   0.01 0.86 0.09 0.02 0.01 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  86.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.   0.08 0.02 0.08 0.07 0.23 0.42 0.04 0.05]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  42.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.05 0.01 0.28 0.01 0.07 0.31 0.17 0.01 0.1 ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  31.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.19 0.03 0.32 0.05 0.03 0.36 0.01 0.   0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  36.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.   0.   0.25 0.   0.04 0.5  0.15 0.   0.07]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  50.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.01 0.16 0.13 0.09 0.31 0.01 0.1  0.18 0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cupping therapy for this recommendation with  31.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.   0.   0.   0.   0.   0.97 0.03 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  97.0 %
## -----------------------------------------

N-gram Vectorization-(tri-quad-quint)gram with two additional categories-risks scrubbed

modalities = pd.read_csv('benefitsContraindications3.csv', encoding = 'unicode_escape') 
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ...                                risksAdverseEffects
## 33  \r\nChiropractic Care for Back Pain\r\nIn this...  ...  Continue Reading Below\r\n\r\nPeople who have ...
## 8   BENEFITS OF MASSAGE\r\n\r\nYou know that post-...  ...                                                NaN
## 46  ll You Need To Know About Massage Gun\r\n31 Au...  ...                                                NaN
## 70  lucy should experience the mindnumbing pleasur...  ...                                                NaN
## 24  \r\nThe Top 7 Benefits of Physical Therapy\r\n...  ...                                                NaN
## 
## [5 rows x 6 columns]
print(modalities.tail())
##                                              Document  ... risksAdverseEffects
## 20  \r\nBenefits of a Physical Therapist Career\r\...  ...                 NaN
## 41  \r\n    Benefit\r\n    Possible Side Effects\r...  ...                 NaN
## 23  The Role of Physical Therapy\r\n\r\nThe role o...  ...                 NaN
## 83  \r\nHow to know where to go for sudden health ...  ...                 NaN
## 50  This futuristic ?gun? could be more effective ...  ...                 NaN
## 
## [5 rows x 6 columns]
def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 33    [Chiropractic, Care, for, Back, Pain, In, this...
## 8     [BENEFITS, OF, MASSAGE, You, know, that, post-...
## 46    [ll, You, Need, To, Know, About, Massage, Gun,...
## 70    [lucy, should, experience, the, mindnumbing, p...
## 24    [The, Top, 7, Benefits, of, Physical, Therapy,...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 33    [chiropractic, care, back, pain, article, chir...
## 8     [benefit, massage, know, post-massage, feeling...
## 46    [need, know, massage, gun, 31, august, 2019, 3...
## 70    [lucy, experience, mindnumbing, pleasure, mass...
## 24    [top, 7, benefit, physical, therapy, laura, sl...
## Name: Document, dtype: object
bow_transformerNgrams = CountVectorizer(analyzer=split_into_lemmas,ngram_range=(3,5)).fit(modalities['Document'])
          
print(len(bow_transformerNgrams.vocabulary_))
## 5102
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerNgrams.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 75)    2
##   (0, 78)    1
##   (0, 94)    1
##   (0, 184)   2
##   (0, 209)   1
##   (0, 242)   1
##   (0, 245)   3
##   (0, 247)   1
##   (0, 248)   1
##   (0, 251)   2
##   (0, 290)   2
##   (0, 298)   1
##   (0, 319)   1
##   (0, 354)   1
##   (0, 355)   4
##   (0, 361)   1
##   (0, 384)   1
##   (0, 400)   1
##   (0, 417)   1
##   (0, 423)   1
##   (0, 437)   2
##   (0, 451)   7
##   :  :
##   (0, 4721)  1
##   (0, 4735)  2
##   (0, 4740)  1
##   (0, 4744)  1
##   (0, 4824)  3
##   (0, 4827)  1
##   (0, 4828)  2
##   (0, 4847)  1
##   (0, 4914)  2
##   (0, 4935)  4
##   (0, 4949)  2
##   (0, 4955)  1
##   (0, 4958)  2
##   (0, 4962)  1
##   (0, 4963)  1
##   (0, 4985)  1
##   (0, 5013)  2
##   (0, 5014)  1
##   (0, 5016)  1
##   (0, 5028)  2
##   (0, 5029)  1
##   (0, 5038)  1
##   (0, 5047)  1
##   (0, 5058)  1
##   (0, 5070)  1
modalities_bow = bow_transformerNgrams.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (87, 5102)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 17813
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 4.01%
modalities_bow
## <87x5102 sparse matrix of type '<class 'numpy.int64'>'
##  with 17813 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:70]
modalities_bow_test = modalities_bow[70:]
modalities_sentiment_train = modalities['Topic'][:70]
modalities_sentiment_test = modalities['Topic'][70:]

print(modalities_bow_train.shape)
## (70, 5102)
print(modalities_bow_test.shape)
## (17, 5102)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                         predictions                      Topic
## 85                               ER                         ER
## 34            chiropractic benefits      chiropractic benefits
## 68                 massage benefits           Not Professional
## 84  mental health services benefits                         ER
## 47             massage gun benefits       massage gun benefits
## 43                 cupping benefits           cupping benefits
## 73                 massage benefits           Not Professional
## 48             massage gun benefits       massage gun benefits
## 12                 massage benefits           massage benefits
## 82                               ER                         ER
## 17        physical therapy benefits  physical therapy benefits
## 65                 massage benefits           Not Professional
## 20        physical therapy benefits  physical therapy benefits
## 41                 cupping benefits           cupping benefits
## 23        physical therapy benefits  physical therapy benefits
## 83                               ER                         ER
## 50             massage gun benefits       massage gun benefits
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.7647058823529411
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[3 0 0 0 0 0 1 0]
##  [0 0 0 0 3 0 0 0]
##  [0 0 1 0 0 0 0 0]
##  [0 0 0 2 0 0 0 0]
##  [0 0 0 0 1 0 0 0]
##  [0 0 0 0 0 3 0 0]
##  [0 0 0 0 0 0 0 0]
##  [0 0 0 0 0 0 0 3]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                                  precision    recall  f1-score   support
## 
##                              ER       1.00      0.75      0.86         4
##                Not Professional       0.00      0.00      0.00         3
##           chiropractic benefits       1.00      1.00      1.00         1
##                cupping benefits       1.00      1.00      1.00         2
##                massage benefits       0.25      1.00      0.40         1
##            massage gun benefits       1.00      1.00      1.00         3
## mental health services benefits       0.00      0.00      0.00         0
##       physical therapy benefits       1.00      1.00      1.00         3
## 
##                        accuracy                           0.76        17
##                       macro avg       0.66      0.72      0.66        17
##                    weighted avg       0.78      0.76      0.75        17
## 
## 
## C:\Users\m\Anaconda2\envs\python36\lib\site-packages\sklearn\metrics\classification.py:1437: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples.
##   'precision', 'predicted', average, warn_for)
## C:\Users\m\Anaconda2\envs\python36\lib\site-packages\sklearn\metrics\classification.py:1439: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples.
##   'recall', 'true', average, warn_for)

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['ER', 'Not Professional', 'chiropractic benefits',
##        'cold stone benefits', 'cupping benefits', 'massage benefits',
##        'massage gun benefits', 'mental health services benefits',
##        'physical therapy benefits'], dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerNgrams.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    if (pr[0][0] == max(pr[0])):
        print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][2]*100,'%')
        
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][3]*100,'%')
        
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][4]*100,'%')
   
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][5]*100,'%')
    
    elif (pr[0][6] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][6]*100,'%')
    
    elif (pr[0][7] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][7]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][8]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.   0.02 0.16 0.19 0.01 0.6  0.01 0.01 0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  60.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.   0.   0.01 0.95 0.03 0.01 0.01 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  95.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.   0.08 0.04 0.12 0.06 0.28 0.33 0.04 0.05]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  33.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.1  0.01 0.11 0.05 0.03 0.5  0.07 0.   0.13]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  50.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.07 0.03 0.29 0.24 0.01 0.34 0.01 0.   0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  34.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.   0.   0.13 0.   0.01 0.72 0.09 0.   0.04]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  72.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.   0.2  0.08 0.16 0.17 0.02 0.02 0.32 0.01]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is mental health therapy for this recommendation with  32.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.  0.  0.  0.  0.  0.9 0.1 0.  0. ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  90.0 %
## -----------------------------------------

N-gram Vectorization-trigram with two additional categories-risks scrubbed

modalities = pd.read_csv('benefitsContraindications3.csv', encoding = 'unicode_escape') 
import regex
def preprocessor(text):
    text = regex.sub('<[^>]*>', '', text)
    emoticons = regex.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = regex.sub('[\W]+', ' ', text.lower()) +\
        ' '.join(emoticons).replace('-', '')
    return text

Reorder the observations so that they are mixed and not grouped together as they are in the original file.

import numpy as np

modalities = modalities.reindex(np.random.permutation(modalities.index))

print(modalities.head())
##                                              Document  ... risksAdverseEffects
## 4   Heading to the spa can be a pampering treat, b...  ...                 NaN
## 60  What is Hot & Cold Stone Therapy?\r\n\r\nHot &...  ...                 NaN
## 22   How Physical Therapy Can Help Your Recovery\r...  ...                 NaN
## 19  \r\nPhysical Therapy for Chronic Pain: What to...  ...                 NaN
## 49  \r\nEverything You Need To Know About Massage ...  ...                 NaN
## 
## [5 rows x 6 columns]
print(modalities.tail())
##                                              Document  ... risksAdverseEffects
## 59  A Guide to Cold Stone Massage\r\n\r\nWhy in th...  ...                 NaN
## 43   Learn All About Cupping Therapy And The Many ...  ...                 NaN
## 81  Signs of an Emergency\r\n\r\nHow quickly do yo...  ...                 NaN
## 28  Mental health providers: Tips on finding one\r...  ...                 NaN
## 71  Hey twitter I'm looking for a lady to massage ...  ...                 NaN
## 
## [5 rows x 6 columns]
def split_into_tokens(review):
    
    return TextBlob(review).words
modalities.Document.head().apply(split_into_tokens)
## 4     [Heading, to, the, spa, can, be, a, pampering,...
## 60    [What, is, Hot, Cold, Stone, Therapy, Hot, Col...
## 22    [How, Physical, Therapy, Can, Help, Your, Reco...
## 19    [Physical, Therapy, for, Chronic, Pain, What, ...
## 49    [Everything, You, Need, To, Know, About, Massa...
## Name: Document, dtype: object
TextBlob("hello world, how is it going?").tags  # list of (word, POS) pairs
## [('hello', 'JJ'), ('world', 'NN'), ('how', 'WRB'), ('is', 'VBZ'), ('it', 'PRP'), ('going', 'VBG')]
import nltk
nltk.download('stopwords')
## True
## 
## [nltk_data] Downloading package stopwords to
## [nltk_data]     C:\Users\m\AppData\Roaming\nltk_data...
## [nltk_data]   Package stopwords is already up-to-date!
from nltk.corpus import stopwords

stop = stopwords.words('english')
stop = stop + [u'a',u'b',u'c',u'd',u'e',u'f',u'g',u'h',u'i',u'j',u'k',u'l',u'm',u'n',u'o',u'p',u'q',u'r',u's',u't',u'v',u'w',u'x',u'y',u'z']
def split_into_lemmas(review):
    #review = unicode(review, 'iso-8859-1')
    review = review.lower()
    #review = unicode(review, 'utf8').lower()
    #review = str(review).lower()
    words = TextBlob(review).words
    # for each word, take its "base form" = lemma 
    return [word.lemma for word in words if word not in stop]

modalities.Document.head().apply(split_into_lemmas)
## 4     [heading, spa, pampering, treat, also, huge, b...
## 60    [hot, cold, stone, therapy, hot, cold, stone, ...
## 22    [physical, therapy, help, recovery, jonathan, ...
## 19    [physical, therapy, chronic, pain, expect, art...
## 49    [everything, need, know, massage, gun, get, re...
## Name: Document, dtype: object
bow_transformerNgrams = CountVectorizer(analyzer=split_into_lemmas,ngram_range=(3,3)).fit(modalities['Document'])
          
print(len(bow_transformerNgrams.vocabulary_))
## 5102
modality4 = modalities['Document'][40]
print(modality4)
## 
## What Is Cupping Therapy?And Should You Try It?
## 
## You're definitely going to have bruises, JSYK.
## By Annie Daly    
## Jun 26, 2018
## Getty Images
## 
## Cupping is the wellness trend that just refuses to die.
## 
## Seriously?raise your hand if you thought cupping therapy would die down back in 2016 after Michael Phelps permanently exited the pool (it me).
## 
## No such luck: Two years later and celebs are still participating in the cupping trend (I see you, Kaley Cuoco and Busy Phillips).
## 
## But uh, what exactly is cupping?and what is it used for?
## Alright, WTF is cupping?
## 
## Cupping is an ancient Chinese therapy that?s based on the belief that certain health problems can be caused by stagnant blood and a poor energy flow through your body.
## 
## To fix or prevent those health issues, cupping practitioners apply cups?typically glass or silicone?to your skin to create a pressure that sucks your skin inward, according to the National Center for Complementary and Integrative Medicine.
## Advertisement - Continue Reading Below
## 
## Cupping practitioners usually place cups on a person's back?though face cupping is becoming *a thing* now too?where they'll either leave the cups in place, or slide them around using lotion or oil, per the NCCIM.
## 
## Either way, the pressure that the cups create draws blood to the affected area, increasing your blood flow overall, says Chiti Parikh, M.D., integrative medicine practitioner at the Weill Cornell Medicine Integrative Health and Wellbeing Center in New York City.
## 
## ?That increased blood flow can relieve muscle tension, improve circulation, and reduce inflammation," says Parikh.
## What's cupping even used for?
## 
## Generally, cupping is used to treat chronic pain?back pain and headaches, in particular, says Parikh. ?It?s all about getting rid of musculoskeletal pain, which is often a physical manifestation of chronic stress,? he adds.
## 
## More often than not, that chronic stress manifests in how you carry yourself. ?We?re often tensing our muscles when we?re stressed?especially when we?re hunched over our computers and our phones?and that muscle tension can result in physical pain, which is what cupping helps reduce," says Parikh.
## Related Story
## What's Causing Your Chronic Back Pain?
## 
## Many people also claim that cupping can help with detoxification, but because "detoxing" really isn't a thing, what they mean is that they are relieving inflammation in the area, Parikh clarifies.
## 
## ?When people are suffering from physical pain, that means that inflammation has increased locally in that area. Cupping, then, improves blood circulation in that area by attracting immune cells to that location to increase the repair and recovery process, so that the swelling can go down,? explains Parikh.
## 
## While there are studies that claim cupping therapy can help reduce chronic pain, like a 2016 study published in the journal Evidence Based Complementary Alternative Medicine, the research is still inconclusive.
## 
## That results of that study in particular, as well as many other studies regarding cupping, may also be due to the placebo effect (i.e., simply believing something is working).
## So, can cupping reduce my stress?
## 
## Cupping may be helpful in treating the more physical manifestations of stress. But, as we all know, physical symptoms are only part of the full story.
## 
## That's why cupping works best when paired with acupuncture to help the mental side of stress, says Parikh. ?Acupuncture releases endorphins, and may be better able to help manage the root cause of your mental stress and anxiety in a more holistic way," she explains. "That?s why the combo of cupping and acupuncture works really synergistically to manage your stress from all areas."
## Related Story
## The Best Way To De-Stress For Your Zodiac Sign
## 
## Plus, while trying cupping on its own may help treat physical pain in more acute conditions, the best and most long-lasting relief comes when you go for the combo. ?The effect is simply more sustainable that way,? she concludes. ?Cupping is hardly ever recommended on its own.?
## Should I try cupping or nah?
## 
## In short: It's probably not going to do any damage?and hey, it might even help that back pain that's been bugging you for weeks, so go ahead and give it a try.
## Advertisement - Continue Reading Below
## 
## Something to keep in mind: Those cups are definitely going to leave big, hickey-like bruises on your skin that can last anywhere from a few days to two weeks?so if that's not something you're interested in, maybe steer clear.
## 
## (It should be noted, however, that the color of the mark varies from person to person and doesn't signify how well the cupping worked.)
## 
## You'll also want to steer clear of cupping if you?re on blood thinners, have trouble with bleeding or clotting, or you have an open wound, cautions Parikh. The same goes for those with very sensitive or thin skin, she adds. ?You should also avoid cupping on any areas where you have delicate skin, because it can cause tearing."
## 
## If these restrictions do not apply to you and you want to give cupping a whirl, it?s important to find a good practitioner. Parikh says the best cupping practitioners are actually?you guessed it?acupuncturists.
## 
## ?To find a good one in your area, I would recommend asking an integrative medicine doctor for a recommendation," says Parikh. "If you don?t know one, your regular doctor will usually be able to refer you to a good one."
## 
## Now, go forth and let the cupping begin
bow4 = bow_transformerNgrams.transform([modality4])
print(bow4)
##   (0, 3) 2
##   (0, 5) 2
##   (0, 7) 7
##   (0, 75)    2
##   (0, 78)    1
##   (0, 94)    1
##   (0, 184)   2
##   (0, 209)   1
##   (0, 242)   1
##   (0, 245)   3
##   (0, 247)   1
##   (0, 248)   1
##   (0, 251)   2
##   (0, 290)   2
##   (0, 298)   1
##   (0, 319)   1
##   (0, 354)   1
##   (0, 355)   4
##   (0, 361)   1
##   (0, 384)   1
##   (0, 400)   1
##   (0, 417)   1
##   (0, 423)   1
##   (0, 437)   2
##   (0, 451)   7
##   :  :
##   (0, 4721)  1
##   (0, 4735)  2
##   (0, 4740)  1
##   (0, 4744)  1
##   (0, 4824)  3
##   (0, 4827)  1
##   (0, 4828)  2
##   (0, 4847)  1
##   (0, 4914)  2
##   (0, 4935)  4
##   (0, 4949)  2
##   (0, 4955)  1
##   (0, 4958)  2
##   (0, 4962)  1
##   (0, 4963)  1
##   (0, 4985)  1
##   (0, 5013)  2
##   (0, 5014)  1
##   (0, 5016)  1
##   (0, 5028)  2
##   (0, 5029)  1
##   (0, 5038)  1
##   (0, 5047)  1
##   (0, 5058)  1
##   (0, 5070)  1
modalities_bow = bow_transformerNgrams.transform(modalities['Document'])
print('sparse matrix shape:', modalities_bow.shape)
## sparse matrix shape: (87, 5102)
print('number of non-zeros:', modalities_bow.nnz)
## number of non-zeros: 17813
print('sparsity: %.2f%%' % (100.0 * modalities_bow.nnz / (modalities_bow.shape[0] * modalities_bow.shape[1])))
## sparsity: 4.01%
modalities_bow
## <87x5102 sparse matrix of type '<class 'numpy.int64'>'
##  with 17813 stored elements in Compressed Sparse Row format>

# Split/splice into training ~ 80% and testing ~ 20%
modalities_bow_train = modalities_bow[:70]
modalities_bow_test = modalities_bow[70:]
modalities_sentiment_train = modalities['Topic'][:70]
modalities_sentiment_test = modalities['Topic'][70:]

print(modalities_bow_train.shape)
## (70, 5102)
print(modalities_bow_test.shape)
## (17, 5102)
print
## <built-in function print>
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[40])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)

prd = pd.DataFrame(predictions)
prd.columns=['predictions']
prd.index=modalities_sentiment_test.index
pred=pd.concat([pd.DataFrame(prd),modalities_sentiment_test],axis=1)
print(pred)
##                         predictions                            Topic
## 2             chiropractic benefits            chiropractic benefits
## 50             massage gun benefits             massage gun benefits
## 79                 massage benefits                 Not Professional
## 67                 massage benefits                 Not Professional
## 47             massage gun benefits             massage gun benefits
## 58              cold stone benefits              cold stone benefits
## 7                  massage benefits                 massage benefits
## 55                 massage benefits              cold stone benefits
## 12                 massage benefits                 massage benefits
## 85                               ER                               ER
## 30  mental health services benefits  mental health services benefits
## 10                 massage benefits                 massage benefits
## 59              cold stone benefits              cold stone benefits
## 43                 cupping benefits                 cupping benefits
## 81                               ER                               ER
## 28  mental health services benefits  mental health services benefits
## 71             massage gun benefits                 Not Professional
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.7647058823529411
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
##  [[2 0 0 0 0 0 0 0]
##  [0 0 0 0 0 2 1 0]
##  [0 0 1 0 0 0 0 0]
##  [0 0 0 2 0 1 0 0]
##  [0 0 0 0 1 0 0 0]
##  [0 0 0 0 0 3 0 0]
##  [0 0 0 0 0 0 2 0]
##  [0 0 0 0 0 0 0 2]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
print(classification_report(modalities_sentiment_test, predictions))
##                                  precision    recall  f1-score   support
## 
##                              ER       1.00      1.00      1.00         2
##                Not Professional       0.00      0.00      0.00         3
##           chiropractic benefits       1.00      1.00      1.00         1
##             cold stone benefits       1.00      0.67      0.80         3
##                cupping benefits       1.00      1.00      1.00         1
##                massage benefits       0.50      1.00      0.67         3
##            massage gun benefits       0.67      1.00      0.80         2
## mental health services benefits       1.00      1.00      1.00         2
## 
##                        accuracy                           0.76        17
##                       macro avg       0.77      0.83      0.78        17
##                    weighted avg       0.70      0.76      0.71        17
## 
## 
## C:\Users\m\Anaconda2\envs\python36\lib\site-packages\sklearn\metrics\classification.py:1437: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples.
##   'precision', 'predicted', average, warn_for)

From the above, precision accounts for type 1 errors (how many real negatives classified as positives-False Positives: TP/(TP+FP)) and type 2 errors (how many real posiives classified as negatives-False Negatives: TP/(TP+FN)) are part of recall.

modalitiesu = modalities.Topic.unique()
mus = np.sort(modalitiesu)
mus
## array(['ER', 'Not Professional', 'chiropractic benefits',
##        'cold stone benefits', 'cupping benefits', 'massage benefits',
##        'massage gun benefits', 'mental health services benefits',
##        'physical therapy benefits'], dtype=object)

def predict_modality(new_review): 
    new_sample = bow_transformerNgrams.transform([new_review])
    pr = np.around(modalities_sentiment.predict_proba(new_sample),2)
    print(new_review,'\n\n', pr)
    print('\n\nThe respective order:\n 0-chiropractic therapy\n 1-cold stone therapy\n 2-cupping therapy\n 3-massage therapy\n 4-massage gun therapy\n 5-mental health therapy\n 6-physical therapy\n\n')
    
    if (pr[0][0] == max(pr[0])):
        print('The max probability is Emergency Room services for this recommendation with ', pr[0][0]*100,'%')
    elif (pr[0][1] == max(pr[0])):
        print('The max probability is Non-Professional services for this recommendation with ', pr[0][1]*100,'%')
        
    elif (pr[0][2] == max(pr[0])):
        print('The max probability is chiropractic therapy for this recommendation with ', pr[0][2]*100,'%')
        
    elif (pr[0][3] == max(pr[0])):
        print('The max probability is cold stone massage for this recommendation with ', pr[0][3]*100,'%')
        
    elif (pr[0][4] == max(pr[0])):
        print('The max probability is cupping therapy for this recommendation with ', pr[0][4]*100,'%')
   
    elif (pr[0][5] == max(pr[0])):
        print('The max probability is massage therapy for this recommendation with ', pr[0][5]*100,'%')
    
    elif (pr[0][6] == max(pr[0])):
        print('The max probability is massage gun therapy for this recommendation with ', pr[0][6]*100,'%')
    
    elif (pr[0][7] == max(pr[0])):
        print('The max probability is mental health therapy for this recommendation with ', pr[0][7]*100,'%')
    
    else:
        print('The max probability is physical therapy for this recommendation with ', pr[0][8]*100,'%')
    
    print('-----------------------------------------\n\n')
predict_modality('Headaches, body sweats, depressed.')
## Headaches, body sweats, depressed. 
## 
##  [[0.   0.01 0.36 0.17 0.06 0.27 0.07 0.03 0.03]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is chiropractic therapy for this recommendation with  36.0 %
## -----------------------------------------
predict_modality('sleepless, energy depraved, cold, tension')
## sleepless, energy depraved, cold, tension 
## 
##  [[0.   0.   0.02 0.87 0.09 0.   0.01 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is cold stone massage for this recommendation with  87.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out 
## 
##  [[0.   0.01 0.03 0.11 0.07 0.17 0.47 0.02 0.11]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  47.0 %
## -----------------------------------------
predict_modality('can\'t move my arm. stuck at home. worried about my neck.')
## can't move my arm. stuck at home. worried about my neck. 
## 
##  [[0.04 0.02 0.12 0.02 0.09 0.21 0.24 0.   0.25]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is physical therapy for this recommendation with  25.0 %
## -----------------------------------------
predict_modality('breathing ragged, tired, headaches, dizzy, nausious ')
## breathing ragged, tired, headaches, dizzy, nausious  
## 
##  [[0.11 0.06 0.32 0.09 0.02 0.35 0.03 0.01 0.02]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  35.0 %
## -----------------------------------------
predict_modality("relief from this pain. can't sleep. feet hurt. chills.")
## relief from this pain. can't sleep. feet hurt. chills. 
## 
##  [[0.   0.   0.24 0.   0.03 0.46 0.13 0.   0.14]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage therapy for this recommendation with  46.0 %
## -----------------------------------------
predict_modality('love this place better than others')
## love this place better than others 
## 
##  [[0.03 0.1  0.07 0.05 0.22 0.03 0.03 0.45 0.02]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is mental health therapy for this recommendation with  45.0 %
## -----------------------------------------
predict_modality('I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple\'s room? What does it cost? Can I change the pressure at any time. I don\'t have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations?')
## I have never had a massage. This is a gift and I want to book an appointment with my wife. Do you have a couple's room? What does it cost? Can I change the pressure at any time. I don't have any pain or aches and my sleep is regular but I drive a lot and get stressed at work with occasional headaches. I workout three times a week and have limited ability in my hamstrings when stretching. I am getting over a chest cold and have some congestion but not contagious. Any recommendations? 
## 
##  [[0.   0.   0.   0.   0.   0.36 0.64 0.   0.  ]]
## 
## 
## The respective order:
##  0-chiropractic therapy
##  1-cold stone therapy
##  2-cupping therapy
##  3-massage therapy
##  4-massage gun therapy
##  5-mental health therapy
##  6-physical therapy
## 
## 
## The max probability is massage gun therapy for this recommendation with  64.0 %
## -----------------------------------------

The trigram n-gram seemed to do pretty well in recommending a health care service.