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
13 views

How to tune LSH implementation for better precision and recall [closed]

I am using locality sensitive hashing (LSH) algorithm/technique with murmur hash in the near-real-time system to find near-duplicate documents. But its precision and recall values are very low (around ...
user avatar
1 vote
0 answers
20 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 ...
user avatar
1 vote
1 answer
15 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 ...
user avatar
  • 131
0 votes
0 answers
24 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 ...
user avatar
  • 2,135
0 votes
0 answers
57 views

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

...
user avatar
0 votes
0 answers
29 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): ...
user avatar
  • 466
0 votes
1 answer
15 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?
user avatar
  • 109
0 votes
0 answers
11 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 ...
user avatar
0 votes
1 answer
40 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. ...
user avatar
0 votes
0 answers
6 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 ...
user avatar
0 votes
0 answers
41 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: ...
user avatar
  • 302
2 votes
1 answer
42 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: ...
user avatar
2 votes
3 answers
63 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 ...
user avatar
  • 187
1 vote
0 answers
11 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 ...
user avatar
1 vote
1 answer
26 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 ...
user avatar
  • 113
0 votes
0 answers
32 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 ...
user avatar
  • 1
0 votes
0 answers
18 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?
user avatar
0 votes
1 answer
131 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 ...
user avatar
0 votes
3 answers
78 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 ...
user avatar
1 vote
1 answer
30 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 ...
user avatar
  • 111
1 vote
2 answers
134 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 ...
user avatar
  • 113
2 votes
1 answer
20 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 ...
user avatar
0 votes
0 answers
10 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 (...
user avatar
0 votes
2 answers
43 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 ...
user avatar
0 votes
1 answer
110 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 ...
user avatar
0 votes
0 answers
28 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 ...
user avatar
0 votes
1 answer
185 views

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

this is my KNN code: ...
user avatar
  • 459
0 votes
0 answers
26 views

Why KNN output predicts all zeros rather one-hot label?

I have trained in supervised way several ML algorithms such as GNB,SVM, KNN. I have multi-class classification model (not multi-label). The input format has ~22 features and the output is one-hot ...
user avatar
0 votes
0 answers
20 views

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

I have a dataset like this: ...
user avatar
  • 459
2 votes
2 answers
121 views

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

This is my script in Rstudio: ...
user avatar
  • 459
0 votes
0 answers
19 views

KNN method with different accuracy

I wrote the knn model with two different methods and I get different results, with a very different accuracy index between the two.. even if they are both knn. This is my actual code: ...
user avatar
  • 459
1 vote
1 answer
31 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, ...
user avatar
0 votes
3 answers
271 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 ...
user avatar
0 votes
0 answers
46 views

KNN search of high-dimensional embedding vectors

I have a large database of n-dimensional numerical vectors. Each vector is the embedding of a vertex into n-dimensional vector space. Vertices belong to a graph, and an algorithm such as node2vec or ...
user avatar
3 votes
1 answer
142 views

New classification in Machine Learning KNN model

This is my example of KNN model (I write it using R): ...
user avatar
  • 459
1 vote
1 answer
44 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 ...
user avatar
1 vote
0 answers
13 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 ...
user avatar
1 vote
1 answer
31 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 ...
user avatar
0 votes
1 answer
64 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. ...
user avatar
  • 1
0 votes
0 answers
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 ...
user avatar
  • 201
1 vote
0 answers
14 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 ...
user avatar
0 votes
0 answers
88 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 ...
user avatar
0 votes
1 answer
52 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 ...
user avatar
  • 3
0 votes
1 answer
54 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 ...
user avatar
  • 1
1 vote
2 answers
128 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?
user avatar
3 votes
1 answer
203 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 ...
user avatar
  • 277
0 votes
1 answer
82 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 ...
user avatar
0 votes
0 answers
43 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 ...
user avatar
4 votes
2 answers
151 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 ...
user avatar
  • 103
1 vote
0 answers
61 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 ...
user avatar