MeanShift
API and practical guide for MeanShift in @kanaries/ml, including when to use it in JavaScript and TypeScript ML workflows.
Clusters.MeanShift
constructor(
bandwidth: number = 1,
max_iter: number = 300,
distanceType: Distance.IDistanceType = 'euclidiean'
)Methods:
fitPredict(samplesX: number[][]): number[]getCentroids(): number[][]
const ms = new MeanShift(2);
const labels = ms.fitPredict(X);
const centers = ms.getCentroids();Practical guide: MeanShift in JavaScript and TypeScript
MeanShift detects high-density regions and infers cluster count automatically from data density.
When to use MeanShift
- You want clustering without specifying the number of clusters.
- Density peaks are more meaningful than centroid partitions.
- Your product needs adaptive grouping behavior over time.
Implementation workflow
- Scale numeric features and choose bandwidth heuristics.
- Fit and inspect discovered modes and assigned labels.
- Tune bandwidth to balance over-fragmentation and over-merging.
JavaScript deployment notes
- Prefer feature scaling for distance-based and gradient-based algorithms to improve stability.
- In browser apps, run heavy training in Web Workers to keep UI interactions smooth.
- Keep a simple baseline from the same module as a fallback model for comparison.
Search intents this page targets
MeanShift JavaScriptMeanShift TypeScriptMeanShift browser machine learning@kanaries/ml MeanShift
FAQ
What problem does MeanShift solve in JavaScript machine learning projects?
MeanShift helps teams implement production-ready ML workflows in browser and Node.js environments with a familiar scikit-learn-style API.
When should I choose MeanShift instead of other Clusters algorithms?
Use MeanShift when it best matches your data shape, labeling strategy, and runtime constraints. Benchmark against at least one alternative in the same module before finalizing defaults.
Can I run MeanShift in both browser and Node.js with @kanaries/ml?
Yes. @kanaries/ml is designed for JavaScript and TypeScript runtimes across browser applications, server-side Node.js services, and edge-friendly workflows.