Composite Rank
Composite Rank Analysis Module for Multi-Factor Retail Decision Making.
Business Context
In retail, critical decisions like product ranging, supplier selection, and store performance evaluation require balancing multiple competing factors. A product might have high sales but low margin, or a supplier might offer great prices but poor delivery reliability. Composite ranking enables data-driven decisions by combining multiple performance metrics into a single, actionable score.
Real-World Applications
- Product Range Optimization: Rank products for listing/delisting decisions based on:
- Sales velocity (units per week)
- Gross margin percentage
- Stock turn rate
- Customer satisfaction scores
-
Return rates
-
Supplier Performance Management: Evaluate suppliers using:
- On-time delivery percentage
- Price competitiveness
- Quality scores (defect rates)
- Payment terms flexibility
-
Order fill rates
-
Store Performance Assessment: Rank stores for investment decisions based on:
- Sales per square foot
- Conversion rates
- Labor productivity
- Customer satisfaction (NPS)
-
Shrinkage rates
-
Category Management: Prioritize categories for space allocation using:
- Category growth rates
- Market share
- Profitability
- Cross-category purchase influence
- Seasonal consistency
How It Works
The module creates individual rankings for each metric, then combines these rankings using aggregation functions (mean, sum, min, max) to produce a final composite score. This approach normalizes metrics with different scales and ensures each factor contributes appropriately to the final decision.
Business Value
- Objective Decision Making: Removes bias by systematically weighing all factors
- Scalability: Can evaluate thousands of products/stores/suppliers simultaneously
- Transparency: Clear methodology that stakeholders can understand and trust
- Flexibility: Different aggregation methods suit different business strategies
- Actionable Output: Direct ranking enables clear cut-off decisions
Key Features: - Creates individual ranks for multiple columns with business metrics - Supports both ascending and descending sort orders for each metric - Combines individual ranks using business-appropriate aggregation functions - Handles tie values for fair comparison - Utilizes Ibis for efficient query execution on large retail datasets
CompositeRank
Creates multi-factor composite rankings for retail decision-making.
The CompositeRank class enables retailers to make data-driven decisions by combining multiple performance metrics into a single, actionable ranking. This is essential for scenarios where no single metric tells the complete story.
Business Problem Solved
Retailers face complex trade-offs daily: Should we keep the high-volume product with low margins or the high-margin product with slow sales? Which supplier offers the best overall value when considering price, quality, and reliability? This class provides a systematic approach to these multi-dimensional decisions.
Example Use Case: Product Range Review
When conducting quarterly range reviews, a retailer might rank products by: - Sales performance (higher is better → descending order) - Days of inventory (lower is better → ascending order) - Customer rating (higher is better → descending order) - Return rate (lower is better → ascending order)
The composite rank identifies products that perform well across ALL metrics, not just excel in one area. Products with the best composite scores are clear "keep" decisions, while those with the worst scores are candidates for delisting.
Aggregation Strategies
Different business contexts require different aggregation approaches: - Mean: Balanced scorecard approach, all factors equally important - Min: Conservative approach, focus on worst-performing metric - Max: Optimistic approach, highlight strength in any area - Sum: Cumulative performance across all dimensions
Actionable Outcomes
The composite rank directly supports decisions like: - Top 20% composite rank → Increase inventory investment - Bottom 20% composite rank → Consider delisting or markdown - Middle 60% → Maintain current strategy, monitor for changes
Source code in openretailscience/analysis/composite_rank.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
df: pd.DataFrame
property
Returns ranked data ready for business decision-making.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Performance data with ranking columns added: - Original metrics (sales, margin, etc.) - Individual rank columns (e.g., sales_rank, margin_rank) - composite_rank: Final combined ranking for decisions |
__init__(df, rank_cols, agg_func, ignore_ties=False, group_col=None)
Initialize the CompositeRank class for multi-criteria retail analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
DataFrame | Table
|
Product, store, or supplier performance data. |
required |
rank_cols |
List[Union[Tuple[str, str], str]]
|
Metrics to rank with their optimization direction. Examples for product ranging: - ("sales_units", "desc") - Higher sales are better - ("days_inventory", "asc") - Lower inventory days are better - ("margin_pct", "desc") - Higher margins are better - ("return_rate", "asc") - Lower returns are better If just a string is provided, ascending order is assumed. |
required |
agg_func |
str
|
How to combine individual rankings: - "mean": Balanced scorecard (most common for range reviews) - "sum": Total performance score (for bonus calculations) - "min": Worst-case performance (for risk assessment) - "max": Best-case performance (for opportunity identification) |
required |
ignore_ties |
bool
|
How to handle identical values: - False (default): Products with same sales get same rank (fair comparison) - True: Force unique ranks even for ties (strict ordering needed) |
False
|
group_col |
str | list[str]
|
Column(s) to partition rankings by group. - None (default): Rank across entire dataset (current behavior) - If specified: Calculate ranks independently within each group Examples for group-based ranking: - "product_category": Rank products within each category - "store_region": Rank stores within their regions - "supplier_type": Rank suppliers within their specialization |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If specified metrics are not in the data or sort order is invalid. |
ValueError
|
If aggregation function is not supported. |
ValueError
|
If group_col is specified but doesn't exist in the data. |
Examples:
>>> # Global ranking: Rank all products together (current behavior)
>>> ranker = CompositeRank(
... df=product_data,
... rank_cols=[
... ("weekly_sales", "desc"),
... ("margin_percentage", "desc"),
... ("stock_cover_days", "asc"),
... ("customer_rating", "desc")
... ],
... agg_func="mean"
... )
>>> # Products with lowest composite_rank should be reviewed for delisting
>>> # Group-based ranking: Rank products within each category
>>> ranker = CompositeRank(
... df=product_data,
... rank_cols=[
... ("weekly_sales", "desc"),
... ("margin_percentage", "desc"),
... ("stock_cover_days", "asc")
... ],
... agg_func="mean",
... group_col="product_category"
... )
>>> # Electronics products ranked against other electronics
>>> # Apparel products ranked against other apparel
Source code in openretailscience/analysis/composite_rank.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |