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
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 ...
  • 377
1 vote
0 answers
72 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
35 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
16 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
29 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,282
0 votes
0 answers
709 views

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

...
0 votes
0 answers
86 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
99 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
13 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
176 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 ...
0 votes
0 answers
111 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
97 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: ...
3 votes
3 answers
201 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 ...
  • 207
1 vote
0 answers
15 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
29 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
0 answers
43 views

Reproducing research results - one-shot classification for MNIST and Fashion-MNIST

I have come across two pieces of research related to one-shot classification of MNIST and Fashion-MNIST images using a 1-nearest neighbour (1-NN) classifier: [1] G. Koch, "Siamese Neural ...
  • 1
0 votes
0 answers
26 views

Ensemble Model for Recommendation Engine

I want to build an ensemble recommendation engine where I can combine Surprise library algorithms like KNN and SVD to achieve the best result. Can anyone know how to ensemble this technique?
0 votes
1 answer
275 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
151 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
34 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
363 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
0 answers
17 views

How to use K-NN imputer without replacing with decimal values example ( 0.75,0.6) instead of binary outcome (yes or no, 1 or 0)?

I am trying to impute some missing categorical values using K-NN imputer, after imputation the missing values are replaced with some decimal numbers. I want to use K-NN as classifier and the output (...
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
188 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
30 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
367 views

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

this is my KNN code: ...
  • 471
0 votes
0 answers
27 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
134 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
33 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
549 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
191 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
85 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
16 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
43 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
105 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
17 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
181 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
56 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
73 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
139 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
350 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 ...
  • 277
0 votes
1 answer
128 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
312 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
79 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 ...
0 votes
1 answer
34 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: ...
2 votes
1 answer
135 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 (...
  • 23