Not Exported
The primary confidence measure (0-1) specific to the pattern type
Number of unique items (tracks, artists, etc.) exhibiting the pattern
Total number of times the pattern has been observed
A normalized confidence score between 0 and 0.95
// Calculate confidence for an artist aversion pattern
const skipRatio = 0.85; // User skips 85% of tracks by this artist
const uniqueTracks = 12; // Pattern observed across 12 different tracks
const totalSkips = 25; // Total of 25 skip events for this artist
const confidence = calculateConfidence(skipRatio, uniqueTracks, totalSkips);
// Returns a value like 0.82 representing high confidence
function calculateConfidence(
baseFactor: number,
uniqueItems: number,
occurrences: number,
): number {
// More unique items and more occurrences = higher confidence
const uniqueItemsFactor = Math.min(1, uniqueItems / 10);
const occurrencesFactor = Math.min(1, occurrences / 20);
// Combine factors, weighting the base factor most heavily
return Math.min(
0.95, // Cap at 0.95
baseFactor * 0.6 + uniqueItemsFactor * 0.2 + occurrencesFactor * 0.2,
);
}
Calculates a normalized confidence score for detected patterns
Generates a standardized confidence score (0-1) that represents how reliable and significant a detected pattern is. This score is used to filter out noise and prioritize patterns for presentation to users.
The confidence algorithm incorporates multiple factors:
The formula applies different weights to each factor:
The result is capped at 0.95 to acknowledge inherent uncertainty in all patterns.