Skip to main content

Retail

Using AI to Compare Retail Product Performance

Istock 2151984085

AI this, AI that. It seems like everyone is trying to shoehorn AI into everything even if it doesn’t make sense. Many of the use cases I come across online are either not a fit for AI or could be easily done without it. However, below I explore a use case that is not only a good fit, but also very much accelerated by the use of AI.

The Use Case

In the retail world, sometimes you have products that don’t seem to sell well even though they might be very similar to another product that does. Being able to group these products and analyze them as a cohort is the first useful step in understanding why.

The Data and Toolset

For this particular exercise I will be using a retail sales dataset from Zara that I got from Kaggle. It contains information about sales as well as the description of the items.

The tools I will be using are:

    • Python
        • Pandas
        • Langchain

High-level actions

I spend a lot of my time design solutions and one thing I’ve learned is that creating a high-level workflow is crucial in the early stages of solutioning. It allows for quick critique, communication, and change, if needed. This particular solution is not very complex, nevertheless, below are the high-level actions we will be performing.

  1. Load the csv data onto memory using Pandas
  2. Create a Vector Store to store our embeddings.
    1. Embed the description of the products
  3. Modify the Pandas dataframe to accommodate the results we want to get.
  4. Create a template that will be sent to the LLM for analysis
  5. Process each product on its own
    1. Get a list of comparable products based on the description. (This is where we leverage the LLM)
    2. Capture comparable products
    3. Rank the comparable products based on sales volume
  6. Output the data onto a new CSV
  7. Load the CSV onto PowerBI for visualization
    1. Add thresholding and filters.

The Code

All of the code for this exercise can be found here

The Template

Creating a template to send to the LLM is crucial. You can play around with it to see what works best and modify it to fit your scenario. What I used was this:

 
template = """<br>    You are an expert business analyst that specializes in retail sales analysis.<br>    The data you need is provided below. It is in dictionary format including:<br>    "Product Position": Where the product is positioned within the store,<br>    "Sales Volume": How many units of a given product were sold,<br>    "Product Category": The category for the product,<br>    "Promotion": Whether or not the product was sold during a promotion.<br>    There is additional information such as the name of the product, price, description, and more.<br>    Here is all the data you need to answer questions: {data}<br>    Here is the question to answer: {question}<br>    When referencing products, add a list of the Product IDs at the end of your response in the following format: 'product_ids = [<id1>, <id2>, ... ]'.<br>"""

When we iterate, we will use the following as the question:

 
question = f"Look for 5 products that loosely match this description: {product['description']}?"

The output

Once python does its thing and iterates over all the products we get something like this:

Product ID Product Name Product Description Sales Volume Comparable Product 1 Comparable Product 2 Group Ranking
185102 BASIC PUFFER JACKET Puffer jacket made of tear-resistant… 2823 133100 128179 1
187234 STRETCH POCKET OVERSHIRT Overshirt made of stretchy fabric…. 2575 134104 182306 0.75

Power BI

We then load the data onto Power BI to visualize it better. This will allow us to not only analyze the data using filtering and conditional formatting, but we can also explore the data even further with Copilot.

Look at the screenshot below. I’ve initially setup conditional formatting so that all the products that rank low within their group are highlighted.

I then used Copilot to ask how all of these relate to each other. It was quick to point out that all of them were jackets.

Pbi Copilot

This arms us with enough information to go down a narrower search to figure out why the products are not performing. Some other questions we could ask are:

  1. Is this data seasonal and only includes summer sales?
  2. How long have these jackets been on sale?
  3. Are they all sold within a specific region or along all the stores?
  4. etc.

Conclusion

Yes, there are many, many use cases that don’t make sense for AI, however there are many that do! I hope that what you just read sparks some creativity in how you can use AI to further analyze data. The one thing to remember is that in order for AI to work as it should, it needs contextual information about the data. That can be accomplished via semantic layers. To know more, got to my post on semantic layers

Do you have a business problem and need to talk to an expert about how to go about it? Are you unsure how AI can help? Reach out and we can talk about it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Roberto Trevino

Roberto is an engineer (M.S.) with a passion for automation, data-driven solutions, and technology in general. He is almost always talking about something new in the technology world and enjoys learning about it. He's also done some pretty interesting stuff both personal and professional. Currently, he develops solutions for all sorts of clients at Perficient, Inc. His strongest competency is Analytics and Business Intelligence, but has experience designing a plenitude of solutions and integrations ranging from front-end and client-facing to back-end, transactional and server-side.

More from this Author

Follow Us