Classification Using Nearest Neighbors

Pairwise Distance Metrics

Categorizing query points based on their distance to points in a training data set can be a simple yet effective way of classifying new points. You can use various metrics to determine the distance, described next. Use pdist2 to find the distance between a set of data and query points.

Distance Metrics

Given an mx-by-n data matrix X, which is treated as mx (1-by-n) row vectors x1x2, ..., xmx, and an my-by-n data matrix Y, which is treated as my (1-by-n) row vectors y1y2, ...,ymy, the various distances between the vector xs and yt are defined as follows:

 

  • Euclidean distance

    d2st=(xsyt)(xsyt).

    The Euclidean distance is a special case of the Minkowski distance, where p = 2.

  • Standardized Euclidean distance

    d2st=(xsyt)V1(xsyt),

    where V is the n-by-n diagonal matrix whose jth diagonal element is (S(j))2, where S is a vector of scaling factors for each dimension.

  • Mahalanobis distance

    d2st=(xsyt)C1(xsyt),

    where C is the covariance matrix.

  • City block distance

    dst=n?j=1?xsjytj?.

    The city block distance is a special case of the Minkowski distance, where p = 1.

  • Minkowski distance

    dst=pGn?j=1?xsjytj?p.

    For the special case of p = 1, the Minkowski distance gives the city block distance. For the special case of p = 2, the Minkowski distance gives the Euclidean distance. For the special case of p = ∞, the Minkowski distance gives the Chebychev distance.

  • Chebychev distance

    dst=maxj{?xsjytj?}.

    The Chebychev distance is a special case of the Minkowski distance, where p = ∞.

  • Cosine distance

    dst=(1xsytG(xsxs)(ytyt)).

  • Correlation distance

    dst=1(xsxs)(ytyt)G(xsxs)(xsxs)G(ytyt)(ytyt),

    where

    xs=1n?jxsj

    and

    yt=1n?jytj.

  • Hamming distance

    dst=(#(xsjytj)/n).

  • Jaccard distance

    dst=#[(xsjytj)((xsj0)(ytj0))]#[(xsj0)(ytj0)].

  • Spearman distance

    dst=1(rsrs)(rtrt)G(rsrs)(rsrs)G(rtrt)(rtrt),

    where

    • rsj is the rank of xsj taken over x1jx2j, ...xmx,j, as computed by tiedrank.

    • rtj is the rank of ytj taken over y1jy2j, ...ymy,j, as computed by tiedrank.

    • rs and rt are the coordinate-wise rank vectors of xs and yt, that is, rs = (rs1rs2, ... rsn) and rt = (rt1rt2, ... rtn).

    • rs=1n?jrsj=(n+1)2.

    • rt=1n?jrtj=(n+1)2.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.

Machine Learning in MATLAB

Train Classification Models in Classification Learner App

Train Regression Models in Regression Learner App

Distribution Plots

Explore the Random Number Generation UI

Design of Experiments

Machine Learning Models

Logistic regression

Logistic regression create generalized linear regression model - MATLAB fitglm 2

Support Vector Machines for Binary Classification

Support Vector Machines for Binary Classification 2

Support Vector Machines for Binary Classification 3

Support Vector Machines for Binary Classification 4

Support Vector Machines for Binary Classification 5

Assess Neural Network Classifier Performance

Naive Bayes Classification

ClassificationTree class

Discriminant Analysis Classification

Ensemble classifier

ClassificationTree class 2

Train Generalized Additive Model for Binary Classification

Train Generalized Additive Model for Binary Classification 2

Classification Using Nearest Neighbors

Classification Using Nearest Neighbors 2

Classification Using Nearest Neighbors 3

Classification Using Nearest Neighbors 4

Classification Using Nearest Neighbors 5

Linear Regression

Linear Regression 2

Linear Regression 3

Linear Regression 4

Nonlinear Regression

Nonlinear Regression 2

Visualizing Multivariate Data

Generalized Linear Models

Generalized Linear Models 2

RegressionTree class

RegressionTree class 2

Neural networks

Gaussian Process Regression Models

Gaussian Process Regression Models 2

Understanding Support Vector Machine Regression

Understanding Support Vector Machine Regression 2

RegressionEnsemble