kmodes_fit

Returns a structure with all required k-modes fitted model parameters. These parameters are used for prediction.

Syntax

model = kmodes_fit(data)

model = kmodes_fit(data,options)

Inputs

data
The dataset on which to perform k-modes clustering.
Type: double
Dimension: matrix
options
Type: struct
init
The method to use when choosing the initial centroids.
Type: string
'random': The function chooses ‘n_clusters’ number of data points at random to be selected as the initial centroids. (default)
'huang': The function chooses ‘n_clusters’ number of data points using Huang initialization.
n_clusters (default: 3)
Type: integer
The number of clusters to form and of centroids to generate.
dissim
The dissimilarity function to be used when calculating and selecting the centroids.
Type: string
'simple': The function uses simple dissimilarity to cluster and segregate centroids. (default)
'ng': The function uses NG dissimilarity to cluster and segregate centroids.
'cao': The function uses CAO dissimilarity to cluster and segregate centroids.
maxiter (default: 100)
Type: integer
The maximum number of iterations of the k-modes algorithm in a single run.
remove_header (default: true or 1)
Type: Boolean
Remove the first row of the dataset if set to true. Normally the first row of the data contains the names of the features, which are not used for k-modes clustering.

Outputs

model
Type: struct
Model parameters in the following format:
centroids
The final list of centroids after computation.
assignments (default: 3)
The list of all cluster assignments for each data points in the dataset.
dissim (default: 'simple')
The dissimilarity function used.

Example

Usage of kmodes_fit without options:

data = [1 0 1 2; 1 1 1 2; 1 1 2 0; 0 0 0 0; 0 0 1 2];
model = kmodes_fit(data)

model = struct [
assignments: [Matrix] 5 x 1
1
1
2
3
1
centroids: [Matrix] 3 x 4
1 1 2 0
1 0 1 2
0 0 0 0
dissim: simple
]


Usage of kmodes_fit with options:


data = [1 2; 1 1; 2 2];
options = struct;
options.init = 'huang';
options.n_clusters = 2;
options.dissim = 'ng';

>model = struct [