Purchase Recommendation Dashboard Code

Overview

This repository contains the code to create a Streamlit dashboard for analyzing the Purchase Recommendation Dataset. The dashboard provides insights into customer purchase behavior, including top products, spending patterns, and revenue trends.

Features

  • Top 10 Purchased Products: Displays the most popular products purchased.
  • Top Spending Customers: Highlights the customers who spent the most over the year.
  • Monthly Revenue Trends: Shows revenue trends by month.
  • Purchase Distribution: Visualizes the distribution of purchase amounts.
  • Customer Engagement: Analyzes the number of purchases per customer.

Requirements

  • Python 3.7+
  • Libraries:
    • streamlit
    • pandas
    • matplotlib
    • seaborn
    • datasets

Install the required libraries:

pip install streamlit pandas matplotlib seaborn datasets

How to Use

Step 1: Clone the Repository

Clone this repository to your local machine or use it directly in your Hugging Face Space.

Step 2: Run the Dashboard

Run the Streamlit application using the following command:

streamlit run app.py

Step 3: Access the Dashboard

Once the application is running, open the provided URL in your web browser to view the dashboard.

Code Explanation

Loading the Dataset

The dataset is directly loaded from Hugging Face using the datasets library:

from datasets import load_dataset

# Load dataset from Hugging Face
dataset = load_dataset("your-dataset-name")
df = dataset['train'].to_pandas()
df['PurchaseDate'] = pd.to_datetime(df['PurchaseDate'])
df['Month'] = df['PurchaseDate'].dt.to_period('M')

Generating Insights

  • Top Products:
    top_products = df['ProductName'].value_counts().head(10)
    
  • Top Customers:
    top_customers = df.groupby('CustomerName')['AmountSpent'].sum().sort_values(ascending=False).head(10)
    
  • Monthly Revenue:
    monthly_revenue = df.groupby('Month')['AmountSpent'].sum()
    

Creating the Dashboard

The Streamlit application is structured with the following sections:

import streamlit as st

st.title("Purchase Recommendation Dashboard")

st.header("Top 10 Purchased Products")
st.bar_chart(top_products)

st.header("Top Spending Customers")
st.bar_chart(top_customers)

st.header("Monthly Revenue")
st.line_chart(monthly_revenue)

st.header("Distribution of Purchase Amounts")
st.histogram_chart(df['AmountSpent'])

st.header("Customer Engagement")
st.histogram_chart(df['CustomerName'].value_counts())

Deployment

On Hugging Face Spaces

  1. Create a Space: Navigate to Hugging Face Spaces and create a new space.
  2. Choose Streamlit SDK: Select Streamlit as the SDK.
  3. Upload Files: Upload the app.py file containing the dashboard code. No need to upload the dataset, as it is loaded from Hugging Face.
  4. Deploy: The space will automatically install dependencies and deploy the application.

Example Output

  • Top Products: Bar chart showing the most purchased products.
  • Top Customers: Bar chart highlighting customers with the highest spending.
  • Monthly Revenue: Line chart showing revenue trends.
  • Purchase Distribution: Histogram of purchase amounts.
  • Customer Engagement: Histogram of customer purchase frequencies.

License

This code is provided under the MIT License. Feel free to use, modify, and distribute it.

Contact

For questions or issues, please contact [Your Name/Organization] at [Your Email].

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model is not currently available via any of the supported third-party Inference Providers, and HF Inference API was unable to determine this model's library.