Kernel Kmeans

Version (4.1 KB) by Mo Chen
kernel kmeans algorithm


Updated 11 Mar 2017

View License

This function performs kernel kmeans algorithm. When the linear kernel (i.e., inner product) is used, the algorithm is equivalent to standard kmeans algorithm. Several nonlinear kernel functions are also provided. Upon request, I also include a prediction function for out-of-sample inference. Please try following code for a demo:
clear; close all;
d = 2;
k = 3;
n = 500;
[X,label] = kmeansRnd(d,k,n);
init = ceil(k*rand(1,n));
[y,mse,model] = knKmeans(X,init,@knLin);
idx = 1:2:n;
Xt = X(:,idx);
t = knKmeansPred(model, Xt);
This function is now a part of the PRML toolbox (

Cite As

Mo Chen (2023). Kernel Kmeans (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Statistics and Machine Learning Toolbox in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes


fix incompatibility issue due the stupid API change of function unique()
Improve the code and fix a bug of returning energy
update description


fix a minor bug of returning energy

remove empty clusters

add sample data and detail description