# Questions tagged [k-nn]

K-Nearest Neighbor (K-NN) is a classification algorithm that determines the label of some data point based on the most common label of the closest k other points.

160 questions
Filter by
Sorted by
Tagged with
11 views

### Comparison of classifier confusion matrices

I tried implementing Logistic regression, Linear Discriminant Analysis and KNN for the smarket dataset provided in "An Introduction to Statistical Learning" in python. Logistic Regression ...
4k views

### Regression for discrete values?

I am a novice in machine learning/statistical algorithms, but I have worked with some simple classifiers and regression. I would like some opinions on whether I am going the right direction or not, ...
8 views

### What is the principial difference between zero-shot learning and k-NN and clusterization based methods?

One can consider clustering and k-NN to be a zero-shot, too? I think there is no much principal difference, except using some neural network architecture (usually it is a transformer) which is used to ...
154 views

### sklearn KNN fit throws out error : value too large for dtype('float64')

I have cleaned the data from nan values and infinite values, the only feature which has a large float is the column 8 (it's a sum) I have no Idea how to fix this last error, I tried all previous ...
17 views

### How to find the right number for a training set for machine learning

I would like to develop a machine learning algorithm using the knn model to perform a classification of my data records. My question is: is there a general method to follow to determine how large my ...
18 views

### Taking the squared Euclidean distance for kNN classification of images

A problem I'm working on states: Computes the squared Euclidean distance between each element of the training set and each element of the test set. Images should be flattened and treated as vectors. ...
79 views

### Using KNN to categorise inventory (physical stock items) - is it the best way?

I'm working on a machine learning problem involving inventory (i.e. physical retail stock), however through the cleaning (outlier removal) process some of the items (via their corresponding ...
56 views

### Missing value Imputation in dataset

I have two separate files for Testing and Training. In the training data, I am dropping rows that contain too many missing values . But , In the test data , I cannot afford to drop the rows so I have ...
7 views

### What is the validation strategy for approximate string search?

I am working a approximate string search algorithm. I am wondering how to go with validating that an algorithm is better than another. I can not come up with validation set, since I have no example of ...
48 views

### How to weigh feature array

I have a feature array of around 4000 elements, extracted from one source. On this array I've extracted 7 more feature from other source and now I basically have a 4007 feature array from each data ...
96 views

### adding a supervising process during knn process

I am trying to improve my KNN regression process (I would like to use sklearn / python, but it doesn't matter).I would like to improve my results and to gain insight. Here is an example: I have data ...
13 views

### Is creating decision surface necessary in k-NN?

I am new to machine learning and I came across this question. *1) [True or False] k-NN algorithm does more computation on test time rather than train time. Solution: A The training phase of the ...
14 views

### K-NN algorithm with maximum distance to be considered a neighbor

Is there a variant of the k-NN algorithm where the label returned is: the average of values of the k nearest neighbors that are closer than a given threshold to the query data point? no value if ...
41 views

### Does knn extend the train dataset by test values during the prediction?

Lets say I have 100 values in my dataset and split it 80% train 20% test. When predicting the last value, is the prediction based on previous 99 (80 test + 19 already predicted values) or only the ...
72 views

### Item-based recommender using K-NN

I'm trying to build an item-based recommender using k-nn. I have a list of items, all of which have some properties (features) in common. ...
124 views

### What does big O mean in KNN optimal weights?

Wiki gives this definition of KNN In pattern recognition, the k-nearest neighbors algorithm (k-NN) is a non-parametric method used for classification and regression. In both cases, the input consists ...
52 views

### KNN efficient implementation

The KNN algorithm is very handy and particularly suited to some of my problems, but I can't find any resources on how to implement it in production. As a comparative example, when I use a neural ...
65 views

### Making Sense of this Error Message

I am using a book and a video to learn how to use KNN method to classify movies according to their genres.This is my code: ...
74 views

### kNN for non-ordinal variables

kNN is a distance-based method, so it requires the input to be in numerical form. I was wondering if it is possible to use kNN imputer for non-ordinal categorical variables (like color). Since the ...
1k views

### Operands Could not be Broadcast with Shapes (19,)(0,)

I have googled and read something similar to the problem I have but I do not seem to know how to fix the error I got from this particular code: ...
54 views

### Recommendations based on other products seen

I am trying to develop a basic book recommender system to get in touch with the field and start learning methods and how to prepare the data. The Dataframe I am using is pretty plain, it has the ...
507 views

### k-Nearest Neighbours with time series data - how to obtain whole-time-period estimators

I have a large dataset for the activities performed by multiple staff in a factory over a long period of time - 01/01/2017 - present. The activities performed by the different staff are recorded at ...
179 views

### Question about reshaping array size for KNN Classifiers

I keep trying to run a new set of data through my KNN Classifier but would recieve the message: ValueError: query data dimension must match training data dimension ...
77 views

### If we dont specify any distance in KNN model, how is n_neighbors parameter calculated?

If we don’t specify the distance, how is the n_neighbors calculated?
32 views

### Algorithms for SMS spam detection

Which among KNN, Logistic and Naive Bayes would yield best results for SMS spam detection? Is there any other efficient approach worth exploring. I am planning to make a python application for SMS ...
16 views

### Mean Accuracy and Standard Error of the Accuracy for KNN Classification algorithm

The given below code snippet is from the assignment of online course IBM ML with Python. Here's the assignment. The used variable names :mean_acc and ...
57 views

### find most dense neighborhood of points in high dimensional space

I'm working on a project where I have many high-dimensional points and I want to find the most dense neighborhood of them. Ideally, out of my ~500 points that are each a 4x300 matrix (300 ms time ...
97 views

### When using KNeighborsClassifier, what is the motivation of using weights="distance"?

When using KNeighborsClassifier, what is the motivation of using weights="distance"? According to the scikit-learn ...
30 views

### how interacting variables (known in statistics as moderating variable) are handled by KNN algorithm?

Can someone intuitively explain how interacting variables are being handled by KNN.according to the book "Introduction to Data Mining": Nearest neighbor classifiers can handle the presence ...
75 views

### KNN accuracy going worse with chosen k

This is my first ever KNN implementation. I was supposed to use (without scaling the data initially) linear regression and KNN models for predicting the loan status(Y/N) given a bunch of parameters ...
56 views

### When using KNN, how do I know which order of the Minkowski distance to use?

I am learning about KNN and ML in general. I know that KNN usually uses second order Minkowski distance (Eucledian Distance), but I assume it cal also use other orders. But what is the benefit to ...
19 views

### Why exactly KNN is outperforming Parzen by a huge margin in classificaton task

I'm trying to implement a Naive Bayes classifier, which uses either of hypercubic Parzen window or KNN to estimate a density function. The data I'm using is Fashion MNIST. The steps I take are that ...
303 views

### KNN Imputation utilize mean or mode?

In my current project, I am doing KNN imputation with K = 5 and I am using sklearn.impute.KNNImputer. I have a mix of continuous and nominal variables(encoded as 0/1 or ordinal ones that have been ...
34 views

### How to fit a KNN and then a linear regression with those neighbors?

How do I fit a KNN to get the $k$ nearest neighbors and then aggregate the those neighbors into a fit using a linear regression (instead of a weighted average) in Scikit-Learn? I've tried creating a ...
80 views

### Machine Learning algorithm for detecting anomalies in large sets of events

Let's start with the following hypothetical preconditions: There is traffic: normal and anomaly. Each traffic sample contains a list of events (of variable size) Events happen in order, the possible ...
148 views

### Date transformation for KNN

I have data set with date features like 01/01/2019 and I would like to use KNN. However, I cannot find a good transformation for dates that has a meaningful ...
25 views

### KNN Variance using a high value of K and cross-validation

it has come to my understanding, that a value of K=1, gives a high variance because we are only using only one data point, hence we are very likely to model the noise in that training example. Bias: ...
1k views

### Coordinate System's influence on $L$ distances (Manhattan and Euclidean)

I don't understand this picture, which says if we change the coordinate system, we would have the same result for $L_2$ distance, whereas, our result would differ for $L_1$ distance. What does it ...
36 views

### Machine Learning - Euclidian Distance Classifier exercise [closed]

I'm taking part in an elective subject at university which mainly focuses on the foundations of Machine Learning. Now we got our first exercise - this task should be done practically in any language (...
36 views

### Applying Sci-kit Learn's kNN algorithm to Fresh Data

While I was studying Scikit-learn's kNN algorithm, I realized that if I use sklearn.model_selection.train_test_split, the provided data gets automatically split ...
554 views

### What is difference between Nearest Neighbor and KNN?

I was taking the tutorial of making Recommendation system , there I read that Nearest Neighbor is different from KNN classifier . Could anyone explain that what is Nearest Neighbor and how it is ...
18 views

### How to get KNN linearly hybridised by two similarities?

I'm writing a KNN (collaborative filtering) hybrid similarity recommender and I need some advice. It is based on this paper. I've currently got 2 datasets. The first one is ...
100 views

### K-Nearest Neighbor Classifier Best K Value

I created a KNeighborsClassifier for my dataset adjusting the k hyper-parameter (the number of neighbors) in a for loop. The k ...
8k views

### Why is cross-validation score so low?

I am using Scikit-Learn for this classification problem. The dataset has 3 features and 600 data points with labels. First I used Nearest Neighbor classifier. ...
51 views

### Why is KNN better at K-Fold Cross Validation than XGBoost or Random Forest?

I've been running K-Fold cross validation multiple times for KNN, random forest and XGBoost. KNN can complete sklearn's cross_val_score, so much faster consistently. They all use the same preprocessed ...
13 views

### Calculate euclidean distances for KNN and cross validation given a 99x16 10 folds

I'm trying to implement KNN classification with cross-validation implementation in python. The data consists of 10 folds of size 99x64, each with their corresponding label of size 99x1. Do I have to ...
777 views

### train_test_split() Error: cannot reshape array of size 900000 into shape (100,100,3) [closed]

I am fairly new to python and I have a program for data classification using the k-nearest neighbor method. But I encountered an error when running the program. Here my source code: ...
17 views

### Difference between KNN-DTW and DTW Template matching?

Is there a distinction between kNN-DTW and DTW template matching? Essentially DTW template matching computes the DTW for each point in the training set, similar to the KNN-DTW algorithm. Is there a ...