PANDORE Version 6 GREYC-IMAGE

pknn



Performs K-Nearest Neighbors Clustering on a set of objects.



Synopsis

pknn attr_base attr_in attr_out k [col_base|-] [col_in|-] [col_out|-]

Description

pknn is a partitioning method for a group of n objects into k clusters. The classifier works based on minimum distance from the query instance to the training samples to determine the K-nearest neighbors. After we gather K nearest neighbors, we take simple majority of these K-nearest neighbors to be the prediction of the query instance.

The distance measure between two objects xi and xj uses the euclidean distance:

    Dij = [ SUM{d=1;n} (xid - xjd)2 ]1/2

where xid is the feature d for the object i and xjd is the feature d for the object j.

Parameters

Inputs

Outputs

Result

Returns SUCCESS or FAILURE.

Examples

Classifies beans into the jellybean.pan image from sample of each bean stored in the directory 'base' (Unix version).

# Learning
   classes=1;
   for i in base/*.pan
   do
      pim2array ind $i /tmp/tmp1 
      parraysize ind.1 /tmp/tmp1
      size=`pstatus`
      pcreatearray ind.C Ushort $size $classes | pcolcatenateitem /tmp/tmp1 - i-01.pan
      if [ -f base.pan ]
      then pcolcatenateitem i-01.pan base.pan base.pan
      else cp i-01.pan base.pan
      fi
      classes=`expr $classes + 1`
   done 

# Classification
   pproperty 0 jellybeans.pan
   ncol=`pstatus`
   pproperty 1 jellybeans.pan
   nrow=`pstatus`

   pim2array ind jellybeans.pan | pknn ind ind ind 10 base.pan - | parray2im $ncol $nrow 0 ind | pim2rg - out.pan

See also

Classification

C++ prototype

Errc PKnn(const std::string &a_base, const Collection &c_base, const std::string &a_in, const Collection &c_in, const std::string &a_out, Collection &c_out, int K);

Version française

Classification selon les k plus proches voisins.


Author: Alexandre Duret-Lutz