NYC Data Science Academy| Blog
Bootcamps
Lifetime Job Support Available Financing Available
Bootcamps
Data Science with Machine Learning Flagship ๐Ÿ† Data Analytics Bootcamp Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lesson
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories Testimonials Alumni Directory Alumni Exclusive Study Program
Courses
View Bundled Courses
Financing Available
Bootcamp Prep Popular ๐Ÿ”ฅ Data Science Mastery Data Science Launchpad with Python View AI Courses Generative AI for Everyone New ๐ŸŽ‰ Generative AI for Finance New ๐ŸŽ‰ Generative AI for Marketing New ๐ŸŽ‰
Bundle Up
Learn More and Save More
Combination of data science courses.
View Data Science Courses
Beginner
Introductory Python
Intermediate
Data Science Python: Data Analysis and Visualization Popular ๐Ÿ”ฅ Data Science R: Data Analysis and Visualization
Advanced
Data Science Python: Machine Learning Popular ๐Ÿ”ฅ Data Science R: Machine Learning Designing and Implementing Production MLOps New ๐ŸŽ‰ Natural Language Processing for Production (NLP) New ๐ŸŽ‰
Find Inspiration
Get Course Recommendation Must Try ๐Ÿ’Ž An Ultimate Guide to Become a Data Scientist
For Companies
For Companies
Corporate Offerings Hiring Partners Candidate Portfolio Hire Our Graduates
Students Work
Students Work
All Posts Capstone Data Visualization Machine Learning Python Projects R Projects
Tutorials
About
About
About Us Accreditation Contact Us Join Us FAQ Webinars Subscription An Ultimate Guide to
Become a Data Scientist
    Login
NYC Data Science Acedemy
Bootcamps
Courses
Students Work
About
Bootcamps
Bootcamps
Data Science with Machine Learning Flagship
Data Analytics Bootcamp
Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lessons
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook
Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories
Testimonials
Alumni Directory
Alumni Exclusive Study Program
Courses
Bundles
financing available
View All Bundles
Bootcamp Prep
Data Science Mastery
Data Science Launchpad with Python NEW!
View AI Courses
Generative AI for Everyone
Generative AI for Finance
Generative AI for Marketing
View Data Science Courses
View All Professional Development Courses
Beginner
Introductory Python
Intermediate
Python: Data Analysis and Visualization
R: Data Analysis and Visualization
Advanced
Python: Machine Learning
R: Machine Learning
Designing and Implementing Production MLOps
Natural Language Processing for Production (NLP)
For Companies
Corporate Offerings
Hiring Partners
Candidate Portfolio
Hire Our Graduates
Students Work
All Posts
Capstone
Data Visualization
Machine Learning
Python Projects
R Projects
About
Accreditation
About Us
Contact Us
Join Us
FAQ
Webinars
Subscription
An Ultimate Guide to Become a Data Scientist
Tutorials
Data Analytics
  • Learn Pandas
  • Learn NumPy
  • Learn SciPy
  • Learn Matplotlib
Machine Learning
  • Boosting
  • Random Forest
  • Linear Regression
  • Decision Tree
  • PCA
Interview by Companies
  • JPMC
  • Google
  • Facebook
Artificial Intelligence
  • Learn Generative AI
  • Learn ChatGPT-3.5
  • Learn ChatGPT-4
  • Learn Google Bard
Coding
  • Learn Python
  • Learn SQL
  • Learn MySQL
  • Learn NoSQL
  • Learn PySpark
  • Learn PyTorch
Interview Questions
  • Python Hard
  • R Easy
  • R Hard
  • SQL Easy
  • SQL Hard
  • Python Easy
Data Science Blog > Student Works > A POS Tag Approach to Predict Drug Interactions & User Score Rating

A POS Tag Approach to Predict Drug Interactions & User Score Rating

Karthik Uppulury
Posted on Sep 12, 2019

1,2471,247 Comments in moderation

This blog explores the utility of a (NLP) Part-Of-Speech Tag counts based methodology to predict Drug Interactions & User Score Rating

MOTIVATION: In this blog I address a key question pertinent to Drug Interactions that concerns public health in general. Herein I present a model that predicts the number of side-effects incurred to a patient under medical dose. I'll also present a model that predicts the Consumer Score Rating on a Drug Product based on user feedback. Arguably, the Consumer Score Rating model can offer potential business intelligence and insight in order to better streamline marketing strategies to improve sales. It is expected that the model will be especially useful soon after a product is launched in the market for which user reviews are available.

WORKFLOW & QUESTIONS OF INTEREST: Much information pertinent to various drug products is made freely available to public at drugs.com. This information is extracted and made use of to further draw insights and build data-driven applications. To address the specific questions of interest i.e., to predict - (1) the number of Drug Interactions and (2) the Consumer Score Rating, relevant information is extracted from drugs.com. To this end, I developed and implemented a Spider using (Python's) Scrapy. The spider extracted the pertinent user demographic/profile information, user experiences, inter alia, for analysis. This raw data set was utilized to perform NLP Sentiment analysis using Text Blob. The data set was further expanded to add predictor variables that correspond to the Part-Of-Speech Tag counts from each user review. This final data set served as a starting point to build the aforementioned predictive models of interest. The models were built using regression algorithms. Besides the standard regression algorithms (Linear, Lasso, Elastic Net, kNN, Decision Trees), Boosting algorithms such as Adaptive Boosting, Random Forests, Gradient Boosting, Extra Trees were also investigated.

METHODOLOGY: 

  • DATA EXTRACTION: Several popular drug products from drugs.com were included in the model pipeline for predictive analytics and visualization. The spider crawled all web pages (~6500) to collect user reviews for each drug product.  Specifically, from each user post the following quantities/attributes were extracted - (1) user Comment (text data), (2) the Time Duration the consumer used the drug product, (3) the number of FDA Alerts, (4) the Class of the Drug, (5) the Name of the Drug, (6) the user Rating, (7) the number of Useful Reviews for a specific user Comment, (8) the Date the Comment was posted, (9) the Drug Interactions (Major, Moderate and Minor), and (10) the Pathological Condition for which the Drug was consumed. (The code for the Spider can be found from the following github link: https://github.com/uppulury/DrugReview). The following table summarizes the meaning of each variable:
Variable Type Permissible Value
User Comment Text User's comment
Time Duration Categorical 0,1,2,3,4,5,6,7
FDA Alerts Numerical >=0 (integer)
Class Categorical Text
Name Categorical Text
User Rating Numerical (Integer) 1-10
Useful Reviews Numerical (Integer) >=0
Date String String
Drug Interactions Numerical (Integer) >=0
Pathological Condition Categorical Any text
POSTag Count (normalized) Numerical (Rational) 0 to 1
Subjectivity Numerical (Rational) 0 to 1
Polarity Numerical (Rational) -1 to 1

 

  • 880 distinct drug products and 163,000 user reviews were scraped. Hence the sample size of the data set is 163,000.
  • DATA PREPROCESSING: (1) The number of Major, Moderate and Minor Interactions for each Drug Product was extracted from the raw data. (2) In order to quantify the influence of Time Duration (on User Rating) a user consumed a particular product, the Time Duration attribute is ascribed to a categorical (number) variable.
  • Using the Python library - TextBlob, sentiment analysis and part-of-speech tagging was performed for each user comment/review. More specifically, the subjectivity and polarity scores for each review were calculated. The part-of-speech tag counts were normalized. These POS Tag counts and the subjectivity and polarity scores were used as attributes/predictor variables for the data set. It is posited that the POS Tag counts, subjectivity and polarity scores offer improved predictive ability for 'User Rating'. The tag details are as follows from the following table:
  • The attribute of "Useful_Reviews" (i.e., the number of users who find a review useful) is extracted as a string data type from the Spider crawls. This attribute is type cast to a floating point variable.
  • This preprocessed data set is considered as the final data set for the task of developing an ML model to predict the User Rating and the Major Drug Interactions.

FEATURE SELECTION:

DESCRIPTIVE STATISTICS:

  • DISTRIBUTION OF ATTRIBUTES: Each feature in plotted to understand their distribution.

  • CORRELATION MATRIX: The correlation matrix reveals interesting correlations among feature attributes of the POS Tag counts of user provided reviews and the extracted features (using the python spider) such as user-rating, time-duration, etc. The correlation matrix holds promise for further ML modeling tasks.

(The code for the descriptive statistics and the two models is available from the following git repository: https://github.com/uppulury/DrugReview)

USER-RATING MODEL:

  • Spot Check of Algorithms: The preprocessed data set was split into 80/20 train/validation sets using Scikit-learn's "train_test_split" function. Using 10-Fold Cross Validation, the following Regression algorithms were tested on the training data set i.e., Linear Regression, Lasso, ElasticNet, kNN and CART. The data is modeled using regression algorithms using the scoring metric of 'neg_mean_squared_error'.

  • Testing Algorithms on Standardized Data: Owing to a near Gaussian like distribution and/or single exponential like distribution in the data set (especially features of polarity, subjectivity, FDA alerts, etc) the training data set was standardized using Scikit-learn's Standard Scaler tool. Algorithms were tested on this standardized data using 10-Fold CV (results are shown in the plot below)

 

  • Boosting/Bagging Algorithms on Standardized Data: Adaptive Boosting, Random Forests and Extra Tree algorithms were tested on the standardized data sets (shown below) to evince the Extra Trees algorithm achieved a better score in comparison to RF and Adaptive Boosting. An interesting trend is observed in the case of boosting/bagging algorithms in that similar trend lines appear across various algorithms for the POS Tag model versus the Base Case model (i.e., without POS Tag features). However, in the case of Random Forests and Extra Tree Regressors the POS Tag count features improve the scoring metric by 4-5 units with a better improvement evinced for Extra Trees Regressor (5 units).

 

  • The ML model was fine tuned for optimal hyper parameters using Extra Trees Regressor and the Grid Search CV approach. 100 tree estimators for the model yielded optimal scoring output beyond which the the scoring output tended to flatten out with increasing number of trees. Hence, a total of 100 trees were utilized to finalize the ML model to predict the User-Rating.

  • The finalized model was fitted using the training data set and scored on the validation set. The POS Tag model produced a score of 4.58 versus a score of 9.87 for a model without POS Tag count features in the model using the 'mean_squared_error' scoring metric. Hence, it is concluded and proposed that the predictive model with POS Tag count features/attributes in combination with the Extra Trees Regressor (and NLP tools) is to predict the User-Rating from user feedback.

MAJOR-INTERACTIONS MODEL:

The above approach was applied to predict the property of 'Major-Interactions' that a drug had with other drugs that were simultaneously consumed by a user. The figures below summarize the results. The model with the POS Tag approach gained only modest improvements compared to a model without POS Tag count features. 

(1) Spot Check Algorithms:

 

(2) Test Algorithms on Standardized Data:

 

(3) Boosting/Bagging Algorithms on Standardized Data:

 

(4) FINE-TUNING: 

The finalized model with 100 trees was fitted and scored to predict the Major-Interactions variable to evince a mean squared error of 1.76 for the POS Tag model versus a score of 1.38 for the base case model (without POS Tag features). Owing to a large variation in the target variable more advanced feature selection methods will be needed to build useful predictive models in this scenario.

  • SUMMARY: The quantitative range of the target variables in each of the studied model (i.e., 'Major-Interactions' and 'User-Rating') amount to variances of ~ 17370 and 11 respectively. It is quite possible due to the high variance in the Major-Interactions target variable, the POS Tag count approach could have suffered marginal gains from the scoring algorithms. Nevertheless, to engineer more features to a raw data set of size 163,000 using POS Tag counts is still interesting in it's own right to probe a select class of regression problems i.e., User Rating model in this case. Hence, it is concluded that depending on the nature of the data set itself the POS Tag counts can potentially offer useful insights into predicting target variables with confidence.

About Author

Karthik Uppulury

View all posts by Karthik Uppulury >

Leave a Comment

Cancel reply

You must be logged in to post a comment.

No comments found.

View Posts by Categories

All Posts 2399 posts
AI 7 posts
AI Agent 2 posts
AI-based hotel recommendation 1 posts
AIForGood 1 posts
Alumni 60 posts
Animated Maps 1 posts
APIs 41 posts
Artificial Intelligence 2 posts
Artificial Intelligence 2 posts
AWS 13 posts
Banking 1 posts
Big Data 50 posts
Branch Analysis 1 posts
Capstone 206 posts
Career Education 7 posts
CLIP 1 posts
Community 72 posts
Congestion Zone 1 posts
Content Recommendation 1 posts
Cosine SImilarity 1 posts
Data Analysis 5 posts
Data Engineering 1 posts
Data Engineering 3 posts
Data Science 7 posts
Data Science News and Sharing 73 posts
Data Visualization 324 posts
Events 5 posts
Featured 37 posts
Function calling 1 posts
FutureTech 1 posts
Generative AI 5 posts
Hadoop 13 posts
Image Classification 1 posts
Innovation 2 posts
Kmeans Cluster 1 posts
LLM 6 posts
Machine Learning 364 posts
Marketing 1 posts
Meetup 144 posts
MLOPs 1 posts
Model Deployment 1 posts
Nagamas69 1 posts
NLP 1 posts
OpenAI 5 posts
OpenNYC Data 1 posts
pySpark 1 posts
Python 16 posts
Python 458 posts
Python data analysis 4 posts
Python Shiny 2 posts
R 404 posts
R Data Analysis 1 posts
R Shiny 560 posts
R Visualization 445 posts
RAG 1 posts
RoBERTa 1 posts
semantic rearch 2 posts
Spark 17 posts
SQL 1 posts
Streamlit 2 posts
Student Works 1687 posts
Tableau 12 posts
TensorFlow 3 posts
Traffic 1 posts
User Preference Modeling 1 posts
Vector database 2 posts
Web Scraping 483 posts
wukong138 1 posts

Our Recent Popular Posts

AI 4 AI: ChatGPT Unifies My Blog Posts
by Vinod Chugani
Dec 18, 2022
Meet Your Machine Learning Mentors: Kyle Gallatin
by Vivian Zhang
Nov 4, 2020
NICU Admissions and CCHD: Predicting Based on Data Analysis
by Paul Lee, Aron Berke, Bee Kim, Bettina Meier and Ira Villar
Jan 7, 2020

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day ChatGPT citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay football gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income industry Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI

NYC Data Science Academy

NYC Data Science Academy teaches data science, trains companies and their employees to better profit from data, excels at big data project consulting, and connects trained Data Scientists to our industry.

NYC Data Science Academy is licensed by New York State Education Department.

Get detailed curriculum information about our
amazing bootcamp!

Please enter a valid email address
Sign up completed. Thank you!

Offerings

  • HOME
  • DATA SCIENCE BOOTCAMP
  • ONLINE DATA SCIENCE BOOTCAMP
  • Professional Development Courses
  • CORPORATE OFFERINGS
  • HIRING PARTNERS
  • About

  • About Us
  • Alumni
  • Blog
  • FAQ
  • Contact Us
  • Refund Policy
  • Join Us
  • SOCIAL MEDIA

    ยฉ 2025 NYC Data Science Academy
    All rights reserved. | Site Map
    Privacy Policy | Terms of Service
    Bootcamp Application