Questions tagged [knn]

In pattern recognition, k-nearest neighbors (k-NN) is a classification algorithm used to classify example based on a set of already classified examples. Algorithm: A case is classified by a majority vote of its neighbors, with the case being assigned to the class most common amongst its K nearest neighbors measured by a distance function. If K = 1, then the case is simply assigned to the class of its nearest neighbor.

The idea of the k-nearest neighbors (k-NN) algorithm is using the features of an example - which are known, to determine the classification of it - which is unknown.

First, some classified samples are supplied to the algorithm. When a new non-classified sample is given, the algorithm finds the k-nearest neighbors to the new sample, and determines what should its classification be, according to the classification of the classified samples, which were given as training set.

The algorithm is sometimes called lazy classification because during "learning" it does nothing - just stores the samples, and all the work is done during classification.

Algorithm

The k-NN algorithm is among the simplest of all machine learning algorithms. A shortcoming of the k-NN algorithm is that it is sensitive to the local structure of the data.

The training examples are vectors in a multidimensional feature space, each with a class label. The training phase of the algorithm consists only of storing the feature vectors and class labels of the training samples.

In the classification phase, k is a user-defined constant, and an unlabeled vector (a query or test point) is classified by assigning the label which is most frequent among the k training samples nearest to that query point.

A commonly used distance metric for continuous variables is Euclidean distance. For discrete variables, such as for text classification, another metric can be used, such as the overlap metric (or Hamming distance).

Often, the classification accuracy of k-NN can be improved significantly if the distance metric is learned with specialized algorithms such as Large Margin Nearest Neighbor or Neighbourhood components analysis.

Useful links

1478 questions
-3
votes
1 answer

Java Comparing an array list's specific objects values

I'm doing a KNN Project. I have an arraylist that stores objects that have 4 attributes(int,int,double,string) How do I get to each specific string and compare them with another string( it won't let me use contain function which I need). The thing…
-3
votes
1 answer

KNN implementation in Python

I am trying to implement a simple KNN technique in Python where I am using minute by minute stock price data, and using my x variables as Open, Close and Volume data to predict the next minute Open price. My code is as below:- import numpy as…
-3
votes
2 answers

pairwise subtraction of arrays in python

I have two matrices, A of shape 512*3 and B of shape 1024*3 I want to calculate pairwise subtraction between their rows, so the result would be of shape 512*1024*3 (they are actually arrays of 3D point coordinates : x , y , z and I eventually want…
yld
  • 15
  • 1
  • 9
-3
votes
2 answers

'<' not supported between instances of 'function' and 'function'

Following google developers ML recipes on youtube I wrote this code and tried to run using jupyter python3 notebook.Link: https://www.youtube.com/watch?v=AoeEHqVSNOw I am not able to get result because I am getting this error '<' not supported…
-3
votes
1 answer

kNN classifier in multi-label settings with WEKA

WEKA has profound support for kNN classifiers (many different distances and etc.) Unfortunately WEKA doesn't support multi-label problems. One of the solutions can be to use binary relevance approach. I am not sure whether it's a correct workaround?…
com
  • 2,313
  • 4
  • 24
  • 40
-3
votes
2 answers

what is the meaning of the following lines of code exactly for knn algorithm

I came across this code, but I don't know what the functionality of the following lines of code is: negTrain = neg[:N] posTrain = pos[:N] negTest = neg[N:] posTest = pos[N:] Could somebody guide me?
-4
votes
1 answer

K NN Technique(sanket077047)

i am doing project to classify stress using EEG signal. For this i am using kn N technique but i don't know how to implement this technique.Please help me to solve this query.I am using databse of 24 electrode of EEG and software to use is MATLAB. …
-6
votes
1 answer

Which models of face recognition deep learning?

I need datasetCreator or "record face" to collect picture from users How much picture i need to make face recognition?
1 2 3
98
99