Data Web App for Supermarket Customer Analysis

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.

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

 

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

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


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 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 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 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