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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

How to add query filter to the Nearest Neighbors algorithm?

I have Nearest Neighbors model, built with sklearn sklearn.neighbors.NearestNeighbors, which I use to make content based recommendations. Sometimes I need to ...
  • 101
0 votes
0 answers
17 views

Evaluation parameter in knn

I am using KNN for a regression task It's like that: 1- I normalized the data 2- I calculated the distance of the new data with the previous data (Euclidean distance) 3 - I choose k nearest neighbors ...
0 votes
1 answer
15 views

estimating coordinate correction

I'm working with 3d coordinate data (x,y,z), however I know that the z coordinate is systematically wrong and the error of z is dependant on both x and y. I however do have some data where I know the ...
0 votes
1 answer
21 views

Get multiple predictions from a knn model

I want to my code to return multiple(5) predictions from my trained knn model. I've tried using predict_proba() but it just returns the probabilities and not the names Here is my code: ...
2 votes
1 answer
464 views

Is it sensible to use the ROC curve with an KNN model? And if so why?

I am a beginner doing my first ML project. I am doing a binary supervised classification on an unbalanced dataset and want to use the ROC curve as a performance metric of my models. I am using ...
  • 23
1 vote
0 answers
7 views

Precision and AUROC for which class values

I am a newbie in reading research paper and implementing it by myself. I went through the paper Breast Cancer Survival Prediction from Imbalanced Dataset with Machine Learning Algorithms. Can anyone ...
  • 359
0 votes
0 answers
10 views

How to get the predictions from KNN regression if the inputs are scaled?

I saw that when using KNN classifier, input X should be scaled. However, I also saw KNN can be used for regression too (here). I wonder if the X is needed to be scaled, then their predictions would ...
  • 397
1 vote
0 answers
183 views

KNN using Mahalanobis distance gives low score [closed]

I want to get average score of all possible K but the average accuracy I'm getting is much lower than what's given to me. ...
0 votes
0 answers
19 views

What does "n∼1/d" mean?

Or rather, what is the "~" notation mean? For reference, I'm trying to understand this section from a sci-kit learn documentation page.
  • 101
1 vote
0 answers
40 views

Near duplicate detection algorithms for a near real time system

I'm looking for near-duplicate detection algorithms or techniques for a near-real-time system with large document volumes. I know LSH is the most popular industry-standard algorithm for syntactical ...
1 vote
1 answer
18 views

Algorithm for optimally removing items for improving a nearest neighbors embedding

Let's say that you embed a collection of items belonging to multiple classes into a multidimensional space for predicting unseen future items by K Nearest Neighbors. And in a particular scenario it is ...
  • 131
0 votes
0 answers
30 views

KNN improvements (python)

I rencently had to work on a problem where the best baseline was knn (geolocalised data). I have different targets (binary classification, multiclass classification and regression) and associated ...
  • 2,377
0 votes
0 answers
982 views

How solved "ValueError: y should be a 1d array, got an array of shape () instead."?

...
0 votes
0 answers
101 views

What ways can i find two similar sets of customers use KNN?

I have a study where i want to find users similar to a set of users (SEED). My data looks like a pivot by customer e.g. sample of SEED looks like (note i drop cust_id): ...
  • 486
0 votes
1 answer
215 views

What does a leaf size of 1 in K-neighbors regression mean?

I am doing hyperparameter tuning + cross validation and I'm constantly getting that the optimal size of the leaf should be 1. Should I worry? Is this a sign of overfitting?
  • 109
0 votes
0 answers
16 views

Mixed Data Type Classification / Neighbor Algorithm

Here is a hypothetical simplified dataframe of my problem, which would be low dimensional (20ish features), containing some made-up information about certain dog breeds: Breed Min_Weight Max_Weight ...
0 votes
1 answer
251 views

parallel work on KNN in python

I have a question, related to parallel work on python How I can use Processers =1,2,3... on k nearest neighbor algorithm when K=1, 2, 3,.. to find the change in time spent, speedup, and efficiency. ...
0 votes
0 answers
8 views

Table from results of sknn function (klaR package) won't output

I have a data set with 6 variables that I'm trying to run the sknn function on and then output a table of the results to show k-NN results. I have updated the response variable to a factor to use as ...
  • 101
0 votes
0 answers
149 views

Problems with KNN using tidymodels

I am analyzing a database and I want to perform a KNN. I am using the 'tidymodels' library and when I run the model, I get the following error: ...
  • 302
2 votes
1 answer
127 views

ROC_AUC score is higher before tuning n _neighbors for KNN

This is for multiclass classification. Before tuning the n_neighbors for KNN, these were the results: ...
4 votes
3 answers
393 views

Best way to vectorise names and addresses for similarity searching?

I have a large dataset of around 9 million people with names and addresses. Given quirks of the process used to get the data it is highly likely that a person is in the dataset more than once, with ...
  • 227
1 vote
0 answers
17 views

Nearest neighbor face recognition in eigenspace when using dot product of test set with eigenvectors does not match the performance when using sklearn

I am trying to perform Face recognition using PCA (eigenfaces). I have a set of N training images (of dimensions M=wxh), which I have pre-processed into a vertical ...
1 vote
1 answer
34 views

Recommend different product using NearestNeighbour

I am working on creating a recommendation system which suggests product for the user, based on the other user's data from the same region. My dataset is as below ...
  • 113
0 votes
1 answer
475 views

How does Scikit learn KNN handle categorical input variables?

In some articles, it's said knn uses hamming distance for one-hot encoded categorical variables. Does the scikit learn implementation of knn follow the same way. Also are there any other ways to ...
0 votes
3 answers
186 views

Need for cross-validation in KNN

I read that we need cross-validation in KNN algorithm as the K value that we have found from the TRAIN-TEST of KNN might not be generalizable on unseen data. The logic given was that, the TEST data ...
1 vote
1 answer
36 views

Why feature normalization can increase the biometric recognition accuracy?

In a biometric recognition system, I have noticed that normalizing the extracted wavelet features leads to increasing the recognition accuracy. The classifier used is K-nearest neighbor (KNN), and ...
  • 111
2 votes
2 answers
576 views

Massive difference in accuracy of KNN depending on random_state

pardon the noob question but I am baffled by the following behavior. My model has MASSIVELY different results based on the random seed. I want to train a KNN classifier on the famous Kaggle Titanic ...
  • 123
2 votes
1 answer
22 views

Trim left tail of music in audio file

I have audio files, most of them start with the same music, and then a conversation begins. I want to trim the part of the music (which can be varied in length). I have no labels, I can transcribe the ...
0 votes
2 answers
45 views

How can I know that this works and is correctly done?

Problem: This seems to be very wrong, cannot pinpoint what I am missing or doing wrong here. Should all rows for each column be Normalized? How? I am working on some small thing, and want to get a ...
0 votes
1 answer
278 views

Categorical Variables (Y or N) in KNN Classification?

Practicing KNN and I just had a query about pre-processing, as I understand KNN doesn't work with categorical features. I've read into one-hot-encoding (dummy variables) which I suppose if I applied ...
0 votes
0 answers
39 views

Balanced target variable in KNN classification

In many places, I have seen it only mentioned that predict the label of the query point as the label with more than half of the labels of it's K nearest neighbours. However, I don't see it mentioned ...
0 votes
1 answer
493 views

KNN error: could not find function "train" [closed]

this is my KNN code: ...
  • 471
0 votes
0 answers
31 views

KNN model with two classes in the train dataset and three in classes in test

I have a dataset like this: ...
  • 471
2 votes
2 answers
151 views

How can I define the optimal value of k in the KNN model?

This is my script in Rstudio: ...
  • 471
1 vote
1 answer
34 views

How different classifiers would perform on a particular data set

I am reading through and learning how different ML methods work on different types of data, but I have faced a data set that I am not sure how ML methods, such as decision tree, Naive Bayes, and KNN, ...
-1 votes
3 answers
738 views

How to determine the number of K in KNN

I have a question about how many k values (k=1 or k=5 or k=50) to choose in the following two scenarios. I initially thought choosing k=5 will be the right choice of k for both because it will ...
3 votes
1 answer
219 views

New classification in Machine Learning KNN model

This is my example of KNN model (I write it using R): ...
  • 471
1 vote
1 answer
102 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 ...
1 vote
0 answers
17 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 ...
1 vote
1 answer
55 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 ...
0 votes
1 answer
149 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. ...
  • 1
1 vote
0 answers
20 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 ...
1 vote
0 answers
225 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 ...
0 votes
1 answer
58 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 ...
  • 3
0 votes
1 answer
83 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 ...
  • 1
1 vote
2 answers
145 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?
3 votes
1 answer
458 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 ...
  • 287
0 votes
1 answer
173 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 ...
4 votes
2 answers
449 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 ...
  • 103
1 vote
0 answers
88 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 ...