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
0answers
7 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
1answer
21 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
3answers
44 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
1answer
29 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 ...
1
vote
2answers
23 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 ...
2
votes
1answer
17 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
0answers
7 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
2answers
42 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
1answer
21 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
0answers
17 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
1answer
50 views

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

this is my KNN code: ...
0
votes
0answers
13 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 ...
0
votes
0answers
14 views

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

I have a dataset like this: ...
2
votes
2answers
113 views

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

This is my script in Rstudio: ...
0
votes
0answers
12 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: ...
1
vote
1answer
28 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, ...
0
votes
3answers
83 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 ...
0
votes
0answers
33 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 ...
3
votes
1answer
78 views

New classification in Machine Learning KNN model

This is my example of KNN model (I write it using R): ...
1
vote
1answer
22 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
0answers
11 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
1answer
24 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
1answer
40 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. ...
0
votes
0answers
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 ...
1
vote
0answers
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 ...
0
votes
0answers
20 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
1answer
41 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 ...
0
votes
1answer
48 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
vote
2answers
120 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
1answer
118 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 ...
0
votes
1answer
35 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 ...
0
votes
0answers
20 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 ...
4
votes
2answers
103 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 ...
1
vote
0answers
41 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
1answer
26 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
1answer
50 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 (...
1
vote
2answers
37 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 ...
4
votes
2answers
864 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 ...
2
votes
1answer
37 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 ...
1
vote
0answers
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 ...
0
votes
1answer
92 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 ...
0
votes
0answers
25 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 ...
2
votes
2answers
88 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 ...
2
votes
1answer
135 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 ...
-1
votes
1answer
971 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: ...
0
votes
0answers
23 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 ...
0
votes
0answers
22 views

DTW and kNN-DTW time complexity

I have implemented KNN using a custom DTW metric with sci-kit learn and as shown below: ...
0
votes
0answers
51 views

Is it valid to add MAPE as a margin to prediction output?

I've trained a KNNRegressor on predicting used car prices. A given car's actual selling price is R289,995. My model predicts R260,911. I want to be able to tell the user My knn model predicts the deal ...
0
votes
0answers
35 views
1
vote
0answers
18 views

KNN with high-variance data [closed]

KNN doesn't work well with high-variance data, so how should I fit my data? Here is an example of what the data looks like: