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

Finding Accuracy, Recall, Precision, and F1 from Matlab Confusion Matrix

I'm working on a project to find the highest accuracy between KNN and a Decision Tree for Classification using Matlab. How to calculate the Accuracy, Recall, Precision, and F1 from the output below? ...
Istiamel's user avatar
0 votes
0 answers
15 views

Top hundred nearest neighbour

I have a dataframe with a column called pharmacy number and other columns corresponding to each pharmacy number, there many rows and each row corresponds to pharmacy number. I want to create a ...
Sanket Maiti's user avatar
0 votes
0 answers
17 views

Semantic search with pretrained BERT models giving irrelevant results with high similarity

I'm trying to create a Semantic search system and have experimented with multiple pretrained models from the SentenceTransformers library: LaBSE, MS-MARCO etc. The system is working well in returning ...
Aftaab Zia's user avatar
0 votes
0 answers
44 views

K nearest neighbor with varying feature length

I'm trying to build a tool which predicts the elemental composition of some light source using its emission spectrum with the k nearest neighbor algorithm (I'm using the KNeighborsClassifier from ...
oodani's user avatar
  • 1
0 votes
0 answers
22 views

Rejoin Categorical Labels After Running Cluster Analysis

I'm working on creating a kNN & PCA analysis using 6 variables associated with different schools. The first step is to drop the school name label column which the first column, so only numeric ...
katrone's user avatar
1 vote
0 answers
20 views

How to implement Ant Lion Optimization (ALO) feature selection for KNN Classification Problems?

I have been assigned for a project related to text data classification, i have preprocess and vectorized the data with TF-IDF. For feature selection i am using pyMetahueristic library to implement ALO ...
Physics69's user avatar
0 votes
2 answers
120 views

KNN Accuracy training

After I developed my model using KNN I get the following accuracy: Train Accuracy :: 1 Test Accuracy :: 0.24 What is the accuracy of my model?
user150859's user avatar
3 votes
0 answers
63 views

Where can I find implementation of the various improvements of K-nearest neighbors (KNN)?

I have been facing some challenges where traditional KNN algorithm perform well. I'd like to explore more advanced knn solutions. While researching possible solutions, I came across a paper titled <...
Lucas Morin's user avatar
  • 2,567
0 votes
1 answer
65 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 ...
Egor's user avatar
  • 101
0 votes
0 answers
19 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 ...
Ho3ein H K's user avatar
0 votes
1 answer
18 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 ...
drulludanni's user avatar
0 votes
1 answer
33 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: ...
Genevieve's user avatar
2 votes
1 answer
1k 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 ...
Ludger's user avatar
  • 23
1 vote
0 answers
8 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 ...
Encipher's user avatar
  • 359
1 vote
0 answers
366 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. ...
Ali77pour AHmadi's user avatar
0 votes
0 answers
22 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.
Maxim's user avatar
  • 101
1 vote
0 answers
45 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 ...
Murali Mopuru's user avatar
1 vote
1 answer
28 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 ...
matanster's user avatar
  • 131
0 votes
0 answers
35 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 ...
Lucas Morin's user avatar
  • 2,567
0 votes
0 answers
1k views

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

...
Asma Tolihan's user avatar
0 votes
1 answer
391 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?
Caterina's user avatar
  • 119
0 votes
1 answer
394 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. ...
Salman Al-haddad's user avatar
2 votes
1 answer
186 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: ...
user2807477's user avatar
6 votes
3 answers
1k 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 ...
Sandy Lee's user avatar
  • 247
1 vote
0 answers
19 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 ...
zr0gravity7's user avatar
1 vote
1 answer
49 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 ...
srinath's user avatar
  • 113
0 votes
1 answer
774 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 ...
insomniac's user avatar
0 votes
3 answers
249 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 ...
Bhartendu Kumar's user avatar
1 vote
1 answer
46 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 ...
Noha's user avatar
  • 111
2 votes
2 answers
970 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 ...
Esoog's user avatar
  • 123
3 votes
1 answer
29 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 ...
David Harar's user avatar
0 votes
2 answers
49 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 ...
John Smith's user avatar
0 votes
1 answer
415 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 ...
TheDataPanda's user avatar
0 votes
0 answers
44 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 ...
Hithesh Kk's user avatar
0 votes
1 answer
678 views

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

this is my KNN code: ...
Inuraghe's user avatar
  • 481
0 votes
0 answers
45 views

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

I have a dataset like this: ...
Inuraghe's user avatar
  • 481
2 votes
2 answers
213 views

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

This is my script in Rstudio: ...
Inuraghe's user avatar
  • 481
1 vote
1 answer
38 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, ...
user9532692's user avatar
-1 votes
3 answers
1k 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 ...
user9532692's user avatar
3 votes
1 answer
269 views

New classification in Machine Learning KNN model

This is my example of KNN model (I write it using R): ...
Inuraghe's user avatar
  • 481
1 vote
1 answer
148 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 ...
NoobHere's user avatar
1 vote
0 answers
25 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 ...
Moonwalker's user avatar
1 vote
1 answer
73 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 ...
Inuraghe's user avatar
0 votes
1 answer
188 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. ...
Ryan's user avatar
  • 1
1 vote
0 answers
42 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 ...
Prashant Kumar's user avatar
1 vote
0 answers
321 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 ...
maxime langevin's user avatar
0 votes
1 answer
67 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 ...
nanu's user avatar
  • 3
0 votes
1 answer
109 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 ...
montty's user avatar
  • 1
1 vote
2 answers
170 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?
Karthik Ganesh's user avatar
3 votes
1 answer
660 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 ...
Boom's user avatar
  • 297