The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



CalcContingencyTable


Unit: SDL_membl
Class: TMemBasedLearner
Declaration: function CalcContingencyTable (VarIx, NumNb: integer; var ContTab: TInt2DArray): integer;

A method to test the cluster purity of given clusters is to look at the nearest neighbors of each object of the model data. If the nearest neighbors for all objects belong to the same class the corresponding cluster (defined by its class number) is obviously pure. Thus counting the class assignments of the nearest neighbors results in a contingency table which reflects the purity of the clusters.

The method CalcContingencyTable calculates this contingency table looking at NumNb nearest neighbors. The parameter VarIx is the index of the target variable containing the class numbers. The target variable must be either nominal or ordinal.

Please note that the contingency table implicitly depends on the properties DistMode and ScalingMode. The variables used for the calculation of the nearest neighbors are given by the property VarType. The resulting contingency table is returned in the variable array ContTab, which is a quadratic matrix one column and row larger than the number of classes (the additional column and row contain the margin sums).

The function returns the following error codes:

 0 ... everything is OK
-1 ... invalid Varix
-2 ... VarIx points to a target variable which is neither nominal nor ordinal
-3 ... target variable has too many or too few levels (< 2 or > 100)


Last Update: 2020-Aug-24