CoolFace
Apppublic

jlim04/usda-rd-analytics

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
App README

🌾 USDA Rural Development β€” Digital Analytics Dashboard

An interactive analytics dashboard analyzing 3.97 million users and 6.43 million sessions on the USDA Rural Development website (rd.usda.gov). Built for MGMT 389 at Purdue University.


Dashboard Sections

TabWhat You'll Find
πŸ“Š RD OverviewKPI cards, monthly trends, device share & engagement comparison
πŸ“„ Content PerformanceTop pages, bounce vs. duration scatter, program category breakdown
πŸ‘₯ User Segments3 K-Means clusters with behavioral profiles and service gap assessment
⚠️ Friction & Gaps8 critical friction points with impact ratings and recommendations
πŸ’‘ Recommendations8 data-driven improvements including AI-enabled opportunities
πŸ”¬ Cluster AnalysisElbow curve, silhouette scores, interactive 3D cluster visualization
πŸ” Data ExplorerInteractive summary tables for monthly, device, page, and cluster data

How the Data Was Processed

Step 1 β€” Raw Data

The original dataset was a GA4 export from rd.usda.gov containing 100,000 rows Γ— 51 columns. Each row represented a unique combination of page + day + device type + country. The 51 columns were grouped into four device segments (desktop, mobile, tablet, smart TV) plus a totals section, each containing:

ColumnDescription
active_usersUsers who triggered at least one event
event_countTotal number of events fired
sessionsTotal session count
views_per_sessionAverage pages viewed per session
avg_session_durationAverage time on site in seconds
bounce_rateShare of sessions with no further interaction
exitsSessions that ended on this page
returning_usersUsers who had visited before
total_usersAll users including new and returning

The three columns used for clustering were pulled from the totals segment: total_users (column index 49), bounce_rate (index 46), and avg_session_duration (index 45).

Step 2 β€” Aggregation

The 100K rows were aggregated down to 20 page-level summaries β€” one row per top page β€” by grouping on the page path column (index 4) and computing:

  • β€”Total active users β€” summed across all days, devices, and countries
  • β€”Average bounce rate β€” averaged across all rows for that page
  • β€”Average session duration β€” averaged across all rows for that page

The top 20 pages by total active users were selected for clustering. This covers the highest-traffic content on the site and represents the majority of all user activity. All pages below the top 20 were excluded to keep the feature matrix meaningful β€” with K-Means, including hundreds of near-zero-traffic pages would distort centroid positions.

Step 3 β€” Normalization

All three features were min-max normalized to a 0–1 scale using the formula:

x_normalized = (x - x_min) / (x_max - x_min)

This was necessary because active users ranged from ~60K to ~760K while bounce rate ranged from 0.045 to 0.369 β€” without normalization, active users would dominate the Euclidean distance calculation and the algorithm would cluster almost entirely on traffic volume, ignoring bounce rate and session duration entirely.

Step 4 β€” K-Means Clustering

Library: sklearn.cluster.KMeans Parameters: random_state=42 (for reproducibility), n_init=10, max_iter=300 Input: 20 Γ— 3 matrix of normalized features [users_norm, bounce_norm, duration_norm] K tested: 2 through 8

Optimal k was selected using two independent methods:

  • β€”Elbow Method β€” plots inertia (within-cluster sum of squares) vs k. The steepest drop occurred at k=3, with a 45% SSE reduction from k=2 β†’ k=3 vs. only 34% from k=3 β†’ k=4, indicating diminishing returns beyond 3 clusters
  • β€”Silhouette Score β€” measures how similar each point is to its own cluster vs. other clusters (range βˆ’1 to +1). Score peaked at 0.487 at k=3, the highest value across all tested k, confirming maximum inter-cluster separation with minimum intra-cluster variance

Step 5 β€” Unit of Analysis

An important methodological note: clustering was performed at the page level, not the individual user session level. Each of the 20 data points represents a page, not a person. This is a content-based segmentation approach β€” the assumption is that pages attracting similar behavioral patterns serve similar user types. A true user-level clustering would require session-level data for all 6.43M sessions, which was not available in this export format.

Step 6 β€” Cluster Results

The algorithm produced 3 clusters:

ClusterPagesAvg Users/PageAvg BounceAvg DurationTraffic Share
Navigation & Resources6356,08313.2%64s42.5%
Housing Seekers6292,83117.8%142s35.0%
Business & Grants8141,13026.6%165s22.5%

Traffic share is calculated as each cluster's total users divided by the combined total users across all 20 pages β€” not as a share of the full 3.97M site-wide users.


Important Methodological Note

The app does not load or process the raw CSV at runtime. The 100K-row dataset was analyzed offline using Python. The key metrics β€” page-level averages, K-Means cluster assignments, elbow scores, and silhouette scores β€” were pre-computed and embedded directly into app.py as Python data structures.

This means:

  • β€”All site-wide metrics (total users, sessions, bounce rate, device breakdown, monthly trends) were extracted directly from the real CSV and are accurate
  • β€”All page-level metrics (top 20 pages, their bounce rates, session durations, active users) were extracted directly from the real CSV and are accurate
  • β€”The K-Means cluster assignments shown in the dashboard are pre-computed approximations based on the real page-level features, rather than live sklearn output at runtime

To verify the K-Means inputs, see the KMEANS_FEATURES_RAW DataFrame in app.py β€” it contains all 20 pages with their raw and normalized feature values exactly as fed into the algorithm.


Key Findings

  • β€”Mobile-first audience: 53.9% of users are on mobile, yet session duration is 19% shorter than desktop β€” a critical optimization gap
  • β€”Housing programs dominate: SFHGLP alone drives 760K active users (19% of all traffic) with the lowest bounce rate of any major program page
  • β€”Seasonal drop-off: Traffic peaks Jan–Mar and falls ~41% by October, reflecting seasonal Rural Development program demand cycles
  • β€”Most underserved cluster: Business & Grants users have the longest sessions (165s avg) but the highest bounce β€” high intent with inadequate digital support
  • β€”Low return rate: Only 19.6% of users return β€” major retention opportunity through an application status portal

Tech Stack

  • β€”[Gradio](https://gradio.app/) β€” UI framework
  • β€”[Plotly](https://plotly.com/python/) β€” Interactive charts
  • β€”[Pandas](https://pandas.pydata.org/) β€” Data processing
  • β€”Python 3.13

Data Source

GA4 analytics export from rd.usda.gov (USDA Rural Development only). Dataset: MGMT_389_Dataset β€” 100,000 rows Γ— 51 columns, device-segmented daily page-level data covering a 12-month period.

Course: MGMT 389 β€” Purdue University