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 > R > Data Web App for Supermarket Customer Analysis

Data Web App for Supermarket Customer Analysis

Chance Xu
Posted on Mar 19, 2022

The skills I demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

Data Science Background

Whenever there’s business, there’s a need for customer analysis. To do a project on customer segmentation, I found collected customer data at a supermarket on Kaggle.com. I also built an R Shiny Web App that visualizes the relationships between customer segmentation and behaviors. In the end, I explored the possibilities of using the supermarket data to build a logistic regression model to predict customer behaviors at other businesses.

 

Data Information and Analysis Methods

The customer segmentation data has four categories: People, Products, Promotion, and Place. I focused on three out of the four categories, excluding Promotion. The category People includes all necessary information about customers such as birth year (where we could generate age feature), marital status, incomes, date since becoming customer, and education level. The Product category contains information about the amount customers spent on each product (six types). The Place category shows the means of purchase for each purchase.

I first ran a correlation code using R on the data after routine data cleaning, such as dropping columns not useful for the project and handling NA values. I then did the pivot_longer feature engineering to prepare the dataset for group_by and summarise functions to use ggplot2 to carry out segmentation visualization before deploying the visualizations to R Shiny.

Additional Data Sets

I drew on two additional datasets from Kaggle.com: Starbucks and Airplane customer data, which I intended to use as a test data set for the prediction model to be created from the customer segmentation data. The concurrent features among the three datasets are age level and income level. They are categorical instead of numerical because one of the datasets shows age at the categorical level, and one of the other datasets shows income at the categorical level. The target I could use for my prediction model is binary customer satisfaction rating, i.e., ‘satisfied’ and ‘not satisfied.’

 

Data Visualization

Correlation Plot - Supermarket Dataset

We can tell from the correlation plot above that customer income strongly correlates with purchase frequencies and spending total in a positive way. In contrast, customer income has a strong negative correlation with the store website visit frequency. Other factors that negatively correlate with store website visits are purchase frequency at the physical store and the amount spent on each product. The negative relation is expected because the data sets differentiate purchases made through the store’s website and visits to the store’s website.  Two factors that have a relatively weak correlation with the customer behaviors are the dates since becoming a customer and the year of birth.

The bar plot above shows that for all products, a customer with a primary education background – the lowest level of education in our dataset – spends the least. The behavior is most apparent in their spending on meat products and wines. While logically speaking, there’s a positive relationship between the level of education and income, we will also look at income to further verify our findings here.

The scatter plot proves our assumption above that, as income increases, the amount a customer spent in the last two years also increases, especially on wines and meat products.

As seen from the plot above, customers with primary education spend the least frequently among all educational levels at the supermarket, regardless of purchasing means. However, the same type of customers visits the supermarket’s website the most often.

Though people with lower education levels tend to earn less and thus spend less at the supermarket, they do still frequently visit the supermarket’s website. Therefore, it might be a good strategy to post discounted products on the supermarket’s website before regular-priced products to attract more orders from people with primary education.

The bar plot above shows a stable purchasing total at the supermarket regardless of marital status. However, widows tend to spend a little more than people with other matrimonial groups in the last two years.

Similarly, the bar chart above further proves our finding by showing that customers’ marital status doesn’t seem to impact the purchasing frequency at the supermarket. However, we can tell that customers purchase more frequently at the physical store or websites than catalog and deals purchases.

The scatter plot above shows an un-correlated relationship between spending total at the supermarket and customer year of birth. This finding proves our discovery from the correlation matrix above.

The bar plot above shows that customers’ spending interest at the supermarket tends to decrease over time as they become customers. As there’s no indication of when the data was collected – only that it was first uploaded to Kaggle in 2021, we don’t have a clear time frame for the dataset. Even if 2012 was the first year the supermarket started its business, and there was no record before that year, the trend still holds.

Otherwise, we could expect to see the amount spent (in the past two years as is on the Kaggle.com variable description) increase from 2012 to 2014, because there shouldn’t be any spending in 2012, the spending in 2013 should just be the spending in that one year, and the spending in 2014 should be the sum of the spendings in 2012 and 2013.

To count in possible macroeconomic factors, we look at the plot below. The red line is the consumer price index percentage that reflects the price inflation rate of consumer goods. The blue line is the average wage index percentage that demonstrates the wage increase rate of the employed. The plot tells us that– with the exception of 2013, in which the average wage increase rate is slightly below the consumer price inflation rate– in the range of 2012 to 2014, the average wage increase rates are much higher than the inflation rates. Therefore, our finding that customer spending interest decreases over time makes more sense.

To visualize the above plots on a web page, please visit the Shiny Web App I created.

 

Explore the Relationship among the Supermarket, Starbucks, and Airplane Passenger datasets

To see if I could use the information from the supermarket dataset to predict customer satisfaction at Starbucks and an airplane company based on the customer’s age level and income level, I converted the three data sets’ income, age, and satisfaction to the same categorical classes to make the data sets comparable. The age factor has four levels: “<20,” “20-29,” “30-39,” and “>=40.” The income factor has three levels: “Low,” “Middle,” and “High,” and satisfaction is binary.

After running the xtabs function, we see that the majority of the customers in the supermarket dataset are satisfied with the services at the supermarket, as shown in the tables above. This fact gives a problem for logistic regression because, even if the model predicts all customers are satisfied, the accuracy score of the model will still be high. That means we would be getting false positives for the customers that are not satisfied.

The summary of the logistic regression model above tells us that only the customer group aged 30-39 and the group aged 40 or older have a p-value lower than the standard threshold of 0.05. That indicates that age level and income level don’t obviously impact customer satisfaction.

Data Driven Supervised ML models Forecasting U.S. Rent Prices
Data Driven Supervised ML models Forecasting U.S. Rent Prices

Our model's deviance residual plot (above left) shows high deviance, while the influence plot (above right) tells us most values are of high variance, and some are of immense influence. The big circle in the influence plot is an area we would want to avoid because it shows the point, i.e., a case (should be a combination of factor levels in our case) that has a significant residual and high leverage on the model. It can have an adverse effect on the model if the case is changed or excluded.

I also found Pchisq, after dropping Age as an independent variable from the model, is 0.435; McFadden’s pseudo-R^2 based on the deviance is 0.03, meaning there’s only 3% of the variability in customer satisfaction appears to be explained by the predictors in the model.

 

Conclusion & Future Works

  • People with primary education tend to spend much less in the supermarket than people with higher education background, but they tend to visit the store website more frequently than people with higher education background.
  • The higher the education level, the more people will spend on wines.
  • Customer’s purchasing interest at the same store tends to decrease over time.
  • Year of birth doesn’t affect people’s purchasing habits or spending total at supermarkets.
  • The higher the income, the more people spend in the supermarket or the web, especially higher-priced products.
  • People purchase in the store or on its site more frequently than via catalog and deals purchase.
  • For future work, I plan to look for datasets with a good amount of concurrent numerical and categorical variables for building a model to see if customers’ behaviors can be reasonably predicted from one industry to another. Also, I plan to add more features to the Shiny R web App, such as including a model that allows users to select features and see predictions of customer behaviors.

 

 

Author Links

  • LinkedIn
  • GitHub

 

About Author

Chance Xu

Data Scientist and active CPA passionate about using data science to explore business-driven insights. Graduated with a Bachelor's degree with Mathematics major and Economics & Management major, as well as a Master of Science in Accountancy, Chance is...
View all posts by Chance Xu >

Related Articles

Data Analysis
Car Sales Report R Shiny App
Machine Learning
Ames House Prices Predictions
R Shiny
Forecasting NY State Tax Credits: R Shiny App for Businesses
R
R Shiny Shows Decline in Even Strongest Democracies
Data Visualization
Python Shows Factors Influencing University Retention Rates

Leave 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