Affinity Propagation preferences initialization
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
In Affinity Propagation, the preference value controls how willing each data point is to become an exemplar, which in turn strongly affects the number of clusters produced. Higher preferences usually lead to more exemplars and more clusters, while lower preferences tend to reduce them. Initialization therefore is not a cosmetic detail. It is one of the main tuning levers in the algorithm.
What the Preference Represents
Affinity Propagation clusters data by exchanging responsibility and availability messages between samples. The diagonal of the similarity matrix holds the preference values. Conceptually, that diagonal says how suitable each sample is to serve as a cluster center.
If every sample gets the same preference, you are telling the algorithm to start from a uniform prior belief about exemplar candidacy.
Common Default: Median Similarity
A widely used default is the median of the pairwise similarities. In scikit-learn, when preference=None, the estimator uses the median of the input similarities.
That default is popular because it often produces a moderate number of clusters without requiring much tuning.
This is a reasonable first pass when you do not yet know what cluster count range makes sense.
Raise or Lower the Preference Deliberately
If the default produces too many or too few clusters, move the preference value up or down and re-evaluate.
Because similarities are often negative distances, the numerical direction can feel counterintuitive. The practical rule is simpler: experiment around the default and watch how the number of exemplars changes.
Uniform vs Sample-Specific Preferences
Many examples use one scalar preference for all samples. That is the standard starting point.
You can also provide different preference values per sample if domain knowledge suggests some points are more plausible exemplars than others. That is more advanced and only worth doing when you have a strong reason to bias the clustering.
For most applications, uniform initialization is easier to reason about and easier to reproduce.
Damping and Convergence Still Matter
Preference is not the only sensitive parameter. damping affects numerical stability during message passing. If the algorithm oscillates or produces unstable results, changing preference alone may not solve the issue.
That means tuning usually happens in this order:
- choose a sensible similarity measure
- start with median preference
- adjust preference to influence cluster count
- tune damping if convergence is unstable
Common Pitfalls
- Treating preference as a minor setting when it directly affects the number of clusters.
- Assuming there is one universally correct preference value for every dataset.
- Changing preference without checking whether the similarity measure itself makes sense.
- Forgetting that negative-distance similarities can make preference values look unintuitive.
- Overfitting the cluster count to a desired number without checking cluster quality.
Summary
- Preference controls how likely samples are to become exemplars in Affinity Propagation.
- The median similarity is a common and effective default initialization.
- Higher preferences usually produce more clusters; lower preferences usually produce fewer.
- Uniform preference is the normal starting point, while sample-specific preferences are an advanced option.
- Tune preference together with similarity choice and damping, not in isolation.
Related reading
- After reducing the dimensionality of a dataset, I am getting negative feature values
- Agile User Stories for Machine Learning Project?
- AI / inference problem
- AlexNet architecture for black and white image identification
- Aggregate logs by field value and plot as multiple series using AWS CloudWatch Insights
- Algorithm for automating pairwise significance grouping labels in R
- Aho-Corasick and Proper Substrings
- AI Fastest algorithm to find if path exists?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.