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.
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.
# knitr::knit_engines$set(python = reticulate::eng_python)
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
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import classification_report, f1_score, accuracy_score, confusion_matrix
np.random.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 \nUnitedHealthcare Combats Opioid Crisis with ... ... NaN
## 2 The Safety of Chiropractic Adjustments\nBy La... ... 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?\n\nHot & Col... ... google
## 61 \nBenefits of Hot Stone & Cold Stone Therapy\n... ... google
## 62 Benefits Of Hot & Cold Stone Massage\n\nBenefi... ... google
## 63 \nCool Down! Do you need a cold stone massage?... ... google
## 64 \nCool Off Your Summer with Cold Stone Massage... ... google
##
## [5 rows x 4 columns]
print(modalities.shape)
## (65, 4)
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?\n\nHot & Col... ... google
## 61 \nBenefits of Hot Stone & Cold Stone Therapy\n... ... google
## 62 Benefits Of Hot & Cold Stone Massage\n\nBenefi... ... google
## 63 \nCool Down! Do you need a cold stone massage?... ... google
## 64 \nCool Off Your Summer with Cold Stone Massage... ... 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?\n\n Cupping types\... ... google
## 33 \nChiropractic Care for Back Pain\nIn this Art... ... google
## 5 Massage: Get in touch with its many benefits\n... ... google
## 46 ll You Need To Know About Massage Gun\n31 Augu... ... google
## 32 \nChiropractic Care for Back Pain\nIn this Art... ... google
##
## [5 rows x 4 columns]
print(modalities.tail())
## Document ... InternetSearch
## 61 \nBenefits of Hot Stone & Cold Stone Therapy\n... ... google
## 8 BENEFITS OF MASSAGE\n\nYou know that post-mass... ... google
## 64 \nCool Off Your Summer with Cold Stone Massage... ... google
## 6 25 Reasons to Get a Massage\n\nNovember 5, 201... ... google
## 7 7 Benefits of Massage Therapy\n\nMassage thera... ... 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?\n\n Cupping types\... ... 7603
## 33 \nChiropractic Care for Back Pain\nIn this Art... ... 1464
## 5 Massage: Get in touch with its many benefits\n... ... 5418
## 46 ll You Need To Know About Massage Gun\n31 Augu... ... 5415
## 32 \nChiropractic Care for Back Pain\nIn this Art... ... 2734
##
## [5 rows x 5 columns]
#%matplotlib inline
modalities.length.plot(bins=20, kind='hist')
plt.show()
modalities.length.describe()
## count 65.000000
## mean 4821.461538
## std 2951.435520
## min 380.000000
## 25% 2476.000000
## 50% 4152.000000
## 75% 6789.000000
## max 12736.000000
## Name: length, dtype: float64
print(list(modalities.Document[modalities.length > 4200].index))
## [44, 5, 46, 54, 29, 38, 30, 3, 35, 40, 59, 25, 27, 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 > 420]))
## ['cupping benefits', 'chiropractic benefits', 'massage benefits', 'massage gun benefits', 'chiropractic benefits', 'cold stone benefits', 'massage gun benefits', 'mental health services benefits', 'cupping benefits', 'cupping benefits', 'cupping benefits', 'massage gun benefits', 'cupping benefits', 'massage benefits', 'physical therapy benefits', 'physical therapy benefits', 'mental health services benefits', 'massage benefits', 'physical therapy benefits', 'chiropractic benefits', 'cupping benefits', 'massage benefits', 'cupping benefits', 'cold stone benefits', 'mental health services benefits', 'massage benefits', 'massage benefits', 'physical therapy benefits', 'physical therapy benefits', 'mental health services benefits', 'massage gun benefits', 'massage benefits', 'physical therapy benefits', 'cold stone benefits', 'cupping benefits', 'massage benefits', 'physical therapy benefits', 'chiropractic benefits', 'chiropractic benefits', 'chiropractic benefits', 'chiropractic benefits', 'mental health services benefits', 'massage benefits', 'massage gun benefits', 'massage gun benefits', 'cupping benefits', 'cold stone benefits', 'cold stone benefits', 'chiropractic benefits', 'cupping benefits', 'mental health services benefits', 'massage gun benefits', 'massage gun benefits', 'massage gun benefits', 'cold stone benefits', 'cold stone benefits', 'cold stone benefits', 'physical therapy benefits', 'physical therapy benefits', 'massage gun benefits', 'cold stone benefits', 'cold stone benefits', 'massage benefits', 'massage benefits']
modalities.hist(column='length', by='Topic', bins=5)
plt.show()
def split_into_tokens(review):
#review = unicode(review, 'iso-8859-1')# in python 3 the default of str() previously python2 as unicode() is utf-8
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'][42]
print(modality4)
## What to know about cupping therapy
##
## Does it work?
## Pain relief
## Skin conditions
## Sports recovery
## Side effects and risks
## Takeaway
##
## There is some evidence to suggest that cupping therapy may be beneficial for certain health conditions. However, research into cupping therapy tends to be low-quality. More studies are necessary to understand how cupping therapy works, if it works, and in what situations it may help.
##
## Cupping therapy is a traditional Chinese and Middle Eastern practice that people use to treat a variety of conditions.
##
## It involves placing cups at certain points on a person?s skin. A practitioner creates suction in the cups, which pulls against a person?s skin.
##
## Cupping can either be dry or wet. Wet cupping involves puncturing the skin before starting the suction, which removes some of the person?s blood during the procedure.
##
## Cupping typically leaves round bruises on a person?s skin, where their blood vessels burst after exposure to the procedure?s suction effects.
## Does it work?
## Cupping therapy may help increase or decrease blood flow.
##
## According to a study paper in the journal PLoS One, cupping practitioners claim that it works by creating hyperemia or hemostasis around a person?s skin. This means that it either increases or decreases a person?s blood flow under the cups.
##
## Cupping also has links to acupoints on a person?s body, which are central to the practice of acupuncture.
##
## Many doctors consider cupping therapy a complementary therapy, which means that many do not recognize it as part of Western medicine. This does not mean that it is not effective, however.
##
## Complementary therapies with supporting research may be an addition to Western medicine. However, as the National Center for Complementary and Integrative Health (NCCIH) note, there is not yet enough high-quality research to prove cupping?s effectiveness.
##
## Scientists have linked cupping therapy with a variety of health benefits, although there needs to be more research to determine whether it is effective as a treatment.
## Pain relief
##
## People frequently cite cupping therapy as a form of pain relief. However, while there is some evidence for its effectiveness, scientists need to conduct more high-quality studies to demonstrate this fully.
##
## For example, a study paper in the journal Evidence-based Complementary and Alternative Medicine found some evidence to suggest that cupping may reduce pain. However, its authors note that there were limits to the quality of the studies that showed this.
##
## A meta-analysis that appears in the journal Revista Latina-Americano De Enfermagem claims that there may be evidence for cupping being effective in treating back pain. However, again, the researchers note that most studies were low-quality, and that there is a need for more standardization in future studies.
##
## One study paper in the journal BMJ Open came to a similar conclusion for the effectiveness of cupping for neck pain. The researchers note that there is a need for better-quality studies to determine whether cupping therapy is truly effective.
## Medical News Today Newsletter
## Stay in the know. Get our free daily newsletter
##
## Expect in-depth, science-backed toplines of our best stories every day. Tap in and keep your curiosity satisfied.
##
## Your privacy is important to us
## Skin conditions
##
## A study paper in the journal PLoS One found that there was some evidence for cupping therapy being effective at treating herpes zoster and acne.
##
## However, it notes that the studies that supported these findings were at a high risk of bias. So, more rigorous, high-quality studies are necessary to verify the findings.
## Sports recovery
##
## A study paper in the Journal of Alternative and Complementary Medicine notes that professional athletes are increasingly using cupping therapy as part of their recovery practices.
##
## However, the study found no consistent evidence to show that it was effective for anything related to sports recovery.
## Side effects and risks
## Cupping can cause irritation or damage to the skin.
##
## According to the NCCIH, the side effects of cupping can include:
##
## lasting skin discoloration
## scarring
## burns
## infection
##
## If a person has a skin condition such as eczema or psoriasis, cupping may make it worse on the area where the practitioner applies the cups.
##
## In rare instances, a person may experience more significant internal bleeding or anemia if the practitioner takes too much blood during wet cupping.
##
## According to a study paper that appears in the Journal of Acupuncture and Meridian Studies, cupping can also cause:
##
## headaches
## tiredness
## dizziness
## fainting
## nausea
## insomnia
##
## Due to the poor quality of studies investigating cupping, it is difficult to know how common these side effects are.
##
## If a person has any of these side effects following cupping therapy, they should speak to a medical professional. Some people may have health conditions, such as problems with blood clotting, that making cupping less than ideal.
## Takeaway
##
## There is some evidence to suggest that cupping therapy may be able to help a person with certain health issues. However, there are not enough high-quality studies to support this.
##
## To understand whether cupping therapy is effective, how it works, and what issues it is best for, scientists need to conduct and publish more high-quality research.
##
## If a person finds that cupping therapy relieves their pain or helps their health in another way, and if they do not experience any adverse side effects, cupping may be a very good choice. However, some therapies have better evidence for their effectiveness. Doctors may advise that people consider these first.
##
## A person may choose to use cupping therapy alongside better-evidenced therapies. If this is the case, it is important that they let a medical professional know.
bow4 = bow_transformer.transform([modality4])
print(bow4)
## (0, 182) 1
## (0, 207) 3
## (0, 228) 1
## (0, 242) 1
## (0, 244) 2
## (0, 254) 1
## (0, 281) 1
## (0, 286) 1
## (0, 342) 1
## (0, 345) 2
## (0, 351) 2
## (0, 353) 1
## (0, 375) 1
## (0, 395) 1
## (0, 411) 1
## (0, 419) 2
## (0, 426) 1
## (0, 441) 1
## (0, 448) 1
## (0, 486) 1
## (0, 504) 1
## (0, 528) 1
## (0, 579) 1
## (0, 580) 1
## (0, 588) 2
## : :
## (0, 4310) 21
## (0, 4358) 1
## (0, 4363) 1
## (0, 4378) 1
## (0, 4399) 1
## (0, 4418) 1
## (0, 4421) 2
## (0, 4422) 1
## (0, 4444) 1
## (0, 4469) 1
## (0, 4470) 1
## (0, 4495) 2
## (0, 4545) 2
## (0, 4549) 1
## (0, 4569) 2
## (0, 4579) 1
## (0, 4589) 1
## (0, 4648) 1
## (0, 4678) 2
## (0, 4679) 3
## (0, 4684) 3
## (0, 4711) 6
## (0, 4720) 1
## (0, 4749) 1
## (0, 4764) 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[:53]
modalities_bow_test = modalities_bow[53:]
modalities_sentiment_train = modalities['Topic'][:53]
modalities_sentiment_test = modalities['Topic'][53:]
print(modalities_bow_train.shape)
## (53, 4769)
print(modalities_bow_test.shape)
## (12, 4769)
modalities_sentiment = MultinomialNB().fit(modalities_bow_train, modalities_sentiment_train)
print('predicted:', modalities_sentiment.predict(bow4)[0])
## predicted: cupping benefits
print('expected:', modalities.Topic[42])
## expected: cupping benefits
predictions = modalities_sentiment.predict(modalities_bow_test)
print(predictions)
## ['massage gun benefits' 'massage benefits' 'cold stone benefits'
## 'cold stone benefits' 'physical therapy benefits'
## 'physical therapy benefits' 'massage gun benefits' 'cold stone benefits'
## 'massage benefits' 'cold stone benefits' 'massage benefits'
## 'massage benefits']
print('accuracy', accuracy_score(modalities_sentiment_test, predictions))
## accuracy 0.9166666666666666
print('confusion matrix\n', confusion_matrix(modalities_sentiment_test, predictions))
## confusion matrix
## [[4 1 0 0]
## [0 3 0 0]
## [0 0 2 0]
## [0 0 0 2]]
print('(row=expected, col=predicted)')
## (row=expected, col=predicted)
This model generated a 92% accuracy using multinomial naive bayes.
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 2
## physical therapy benefits 1.00 1.00 1.00 2
##
## accuracy 0.92 12
## macro avg 0.94 0.95 0.94 12
## weighted avg 0.94 0.92 0.92 12
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_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 1-chiropractic therapy\n 2-cold stone therapy\n 3-cupping therapy\n 4-massage therapy\n 5-massage gun therapy\n 6-mental health therapy\n 7-physical therapy\n\n')
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.03 0.5 0.02 0.01 0.01]]
##
##
## The respective order:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-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.79 0.17 0.02 0.01 0. 0. ]]
##
##
## The respective order:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is cold stone massage for this recommendation with 79.0 %
## -----------------------------------------
predict_modality('body aches from working out')
## body aches from working out
##
## [[0.05 0.06 0.12 0.24 0.36 0.07 0.09]]
##
##
## The respective order:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is massage gun therapy for this recommendation with 36.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.35 0. 0.06 0.28 0.12 0. 0.18]]
##
##
## The respective order:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is chiropractic therapy for this recommendation with 35.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:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is massage therapy for this recommendation with 42.0 %
## -----------------------------------------
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:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is massage therapy for this recommendation with 46.0 %
## -----------------------------------------
The above shows that this sentiment put into the function predicted the sentiment to be a 1 rating by 57%, and next best was a 4 rating with 15%
predict_modality('love this place better than others')
## love this place better than others
##
## [[0.09 0.02 0.33 0.02 0.05 0.44 0.05]]
##
##
## The respective order:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is mental health therapy for this recommendation with 44.0 %
## -----------------------------------------
predict_modality('massage guns and cupping are great for my post workout aches')
## massage guns and cupping are great for my post workout aches
##
## [[0. 0. 0. 0. 1. 0. 0.]]
##
##
## The respective order:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is massage gun therapy for this recommendation with 100.0 %
## -----------------------------------------
predict_modality('It looks like bruises on my back. Paranoid somebody will tease me about them. I feel better, but still some aches and pains.')
## It looks like bruises on my back. Paranoid somebody will tease me about them. I feel better, but still some aches and pains.
##
## [[0.04 0. 0.92 0. 0.04 0. 0. ]]
##
##
## The respective order:
## 1-chiropractic therapy
## 2-cold stone therapy
## 3-cupping therapy
## 4-massage therapy
## 5-massage gun therapy
## 6-mental health therapy
## 7-physical therapy
##
##
## The max probability is cupping therapy for this recommendation with 92.0 %
## -----------------------------------------
This was a quick python 3 recommender based on google searched results for those ten topics. The underlying data only used 65 articles online. When entering a phrase for possible reasons customers could have to want a massage or describe a massage or their health and wellness afterwards, the results mostly recommended massage therapy. The one phrase,“I love this place better than others.” recommended mental health therapy and another complaining about not moving his or her arm and having pain in the neck recommended chiropractic therapy. This is based entirely on the tokenized and lemmatized words of the selected articles. Some articles included image descriptions and sponsored ads. It would be helpful to see the word clouds of these articles by topic to visualize the results.