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

KNN regression in R

I'm studying a non-linear regression problem and I have read that K-nearest neighbors regression performs well in this case, is there an R implementation of this regression algorithm?
0
votes
0answers
8 views

What is complexity of Nearest Neigbor graph calculation and why kd/ball_tree works slower than brute?

Consider sklearn NearestNeighbors: nbrs = NearestNeighbors(n_neighbors=2, algorithm=method ).fit(X) # 'ball_tree' distances, indices = nbrs.kneighbors(X) There ...
0
votes
1answer
15 views

Question about reshaping array size for KNN Classifiers

I keep trying to run a new set of data through my KNN Classifier but would recieve the message: ValueError: query data dimension must match training data dimension ...
0
votes
2answers
36 views

Need help understanding data leakage

I am a newbie to this stuff so I am sorry if my question is stupid~ I need help understanding what data leakage between X_train and X_test is and when exactly it happens. I am currently working on a ...
3
votes
2answers
34 views

Which model is better for incremental learning?

I'm trying to implement face recognition. I'm planning to use some model (like DeepFace) to extract discriminative features and then use a classifier to recognize the faces. I'm confused as to which ...
1
vote
2answers
26 views

Identify the parameter causing the anomaly in a multivariate dataset

I have a payment transaction dataset with a large number of predictor variables. I am trying to build a model for anomaly detection and I have evaluated various algorithms/approaches for the same like ...
1
vote
1answer
40 views

Could you help me to resolve this exercise of K-NN?

I am just a young learner in Data Science. Could you help me to resolve this exercise of K-NN? Ex.1 The table below provides a training data set containing six observations, three predictors, and ...
0
votes
2answers
28 views

Leave - one - out - Cross Validation KNN R

I have a dataset and I divided it into test data and train data. Can anyone suggest how to perform LOOCV for KNN regression? Is there any library? ...
0
votes
0answers
28 views

KNN() and SVD() for recommender system

I come here cause I have some troubles (or is it normal ?) with the rating predicted by SVD() and KNNWithMeans(), I'm using the Sckit-Surprise library . Here is context : I have 637 069 rating I ...
2
votes
3answers
68 views

Machine learning on classifying speech

So, I have 9k of 1 second wav files of a person speaking. These are labeled by whether the person speaking is wearing a face mask or not. I am supposed to come up with a machine learning model to ...
0
votes
1answer
32 views

Getting a best k in KNN Algorithm

So, i was learning the KNN Algorithm and there i learnt cross Validation to find a optimal value of k.Now i want to apply grid search to get the optimal value.I found an answer on stack overflow where ...
1
vote
0answers
22 views

Use KNN as a clustering method

I am trying to use KNN as an Unsupervised clustering. Yes, I know KNN is supposed to be a used as a classifier, using I was given a task to use it as a clustering model). I am using this link from ...
0
votes
1answer
38 views

K-Nearest neighbor in transformed space

When googling "weighted KNN", the results appear to be focused on weighting the nearest neighbor values after those neighbors have been determined. I'm looking for something that assigns a level of ...
0
votes
1answer
34 views

How to consider categorical variables in distance based algorithms like KNN or SVM?

For example lets say I have a dataset with independent features age, gender, name, and income. While my dependent variable is load approval status. If I want to use KNN or SVM, do I need to convert ...
0
votes
0answers
11 views

Can someone provide me the code of the MiLoF(Memory Efficient Local Outlier Factor) algorithm?

I have to code the MiLoF algorithm for detecting outliers in an unsupervised manner using non-stationary data. I am attaching the paper which explains the algorithm here. However, there are many ...
0
votes
0answers
23 views

KNN with non-stationary time series data

Given features (X,Y,Z) where X is the target feature, and a matrix of (X,Y,Z) data points ordered chronologically: GOAL: At time i, a prediction for Xi must be generated from the available ...
0
votes
0answers
40 views

Combine features in Machine Learning KNN

I'm trying to build a simple book recommendation system, where I don't have any kind of ratings (no comments, no likes, no 1-5 stars, ...). The information I can use is the following: Book metadata ...
0
votes
2answers
40 views

K-Nearest Neighbour Classifier Best K Value

I created a KNeighborsClassifier for my dataset adjusting the k hyper-parameter (the number of neighbours) in a for loop. The k value was between 1 and 20. The ...
3
votes
3answers
62 views

Why does my KNeighborsClassifier graph look like this?

I'm new to data science/ml and working on using the sklearn libraries to classify data. I'm currently using the KNeighborsClassifier with 5 fold cross validation whilst tweaking the k value but its ...
6
votes
1answer
56 views

How to add data points to a trained KNN

I have a trained KNN, I created with https://github.com/kevinzakka/blog-code/blob/master/knn/knn.py I want to add more data points to the KNN but I am on a raspberry pi so limited by RAM and ...
1
vote
1answer
41 views

Recommendations based on other products seen

I am trying to develop a basic book recommender system to get in touch with the field and start learning methods and how to prepare the data. The Dataframe I am using is pretty plain, it has the ...
0
votes
1answer
71 views

50% accuracy on multiclass classification

I am trying to do a multiclass classification on a significant amount of output labels (1000). I built a model using KNN. The accuracy given by ...
0
votes
1answer
22 views

Generalised data science approach to astronomical catalogue cross-match

I'm interested in performing a cross-match between two source catalogues in an astronomical context. I'll try and explain the context simply. A truth catalogue of sources (each with some position, ...
0
votes
0answers
12 views

How to find top N neighbors of a datapoint in a cluster sorted in increasing order of distance from that point?

I am doing a clustering exercise and I am doing it using K-Means. After doing the clustering part, I have a dataframe that looks something like this : ...
0
votes
1answer
23 views

When using KNN, how do I know which order of the Minkowski distance to use?

I am learning about KNN and ML in general. I know that KNN usually uses second order Minkowski distance (Eucledian Distance), but I assume it cal also use other orders. But what is the benefit to ...
3
votes
2answers
37 views

find most dense neighborhood of points in high dimensional space

I'm working on a project where I have many high-dimensional points and I want to find the most dense neighborhood of them. Ideally, out of my ~500 points that are each a 4x300 matrix (300 ms time ...
1
vote
1answer
44 views

How are images (roughly) clustered when using KNN

When classifying data by KNN, the classes are calculated by using the distance between datapoints. For example, the case of real estate, where the x-axis is the price and the y-axis the size of real ...
1
vote
0answers
15 views

euclidean distance between true value and estimated value as input for knn [closed]

If we apply knn on euclidean distance between true value and estimated value will the results be better in case of data classification?
1
vote
1answer
30 views

How can I compare my regressors?

I am trying to build a regressor for a dataset which gives info about students' school performance and the probability of getting admitted in the University of their choice. The first 5 observations ...
2
votes
1answer
70 views

KNN custom transformer shows same accuracy for every k i set

I built custom trasformer for KNN and i can't figure why my k-number, when i set it, always shows same accuracy... ...
2
votes
2answers
83 views

KNN with mixed data (feature set)

I have a dataset where the feature set consists of hour of the day (between 0 to 23), day of the week (Monday to Sunday), number of shops (a positive integer) and road category (0 to 8 on an ordinal ...
1
vote
1answer
27 views

Which kNN model to chose?

I am trying to tune the "n_neighbors" for a kNN model andI have the following problem : Based on the mean cross validation score the optimal kNN model should be the one with 10 neighbors. On the ...
0
votes
1answer
308 views

Does this line in Python indicate that KNN is weighted?

Does this line in Python indicate that KNN is weighted? clf = KNeighborsClassifier(n_neighbors=5, metric='euclidean', weights='distance') Are the weights the ...
0
votes
0answers
17 views

Combining several Multi-Output-Models into a single Multi-Output-Model

I'm trying to create a k-Nearest-Neighbor based model of 76-dimensional input data $I$ and 44-dimensional output data $O$. Through domain knowledge I know that only certain input dimensions are ...
1
vote
1answer
22 views

Converting Text Entries into values for machine learning - KNN

Consider the following dataset. ...
1
vote
1answer
38 views

Maybe wrong values for precision and recall

I'm trying to do some data mining with RapidMiner studio. I've applied the K-nearest neighbor algorithm with different values of K. As I expected, accuracy increase and after K=5, it decrease. But I ...
0
votes
0answers
506 views

Operands Could not be Broadcast with Shapes (19,)(0,)

I have googled and read something similar to the problem I have but I do not seem to know how to fix the error I got from this particular code: ...
1
vote
1answer
46 views

Making Sense of this Error Message

I am using a book and a video to learn how to use KNN method to classify movies according to their genres.This is my code: ...
1
vote
1answer
363 views

Is Annoy a machine learning algorithm to find nearest neighbor ? and is it similar to K nearest neighbor algorithm?

I was researching about Google universal sentence encoding and i saw that it uses simple neighbor/Annoy to find the nearest vector for semantic-similarity search engine. This is the first time i'm ...
0
votes
0answers
10 views

How to quickly find min, max and mean distance between samples fitted in Nearest Neighbors?

I am familiar only with SciKit Learn implementation of Nearest Neighbors model where one can fit data and execute K-neighbors or radius queries. This model does not provide any statistical information ...
0
votes
1answer
35 views

KNN scoring low compared to Logistic regression in MNIST challenge

KNN gives me a score of 0.76100 while it shows 94% accuracy for my training data (splitted with test_size =0.3) in my jupyter notebook while logistic regression gives me a score of 0.91485 with an ...
0
votes
2answers
560 views

kNN vs Logistic Regression

Good day, I had this question set as optional homework and wanted to ask for some input. Suppose an individual was to take a data set, divide it in half into training and test data sets and then try ...
0
votes
0answers
39 views

Feature importance in SVM

Why is there no command for feature importance in SVM like the one provided in Random Forest feature_importance_ from ...
0
votes
0answers
50 views

Could some explain how to determine the boundary of the root cell of a k-d tree with a concrete example, such as knn on iris dataset?

KNN uses k-d tree to calculate the nearest neighbor(s). Wiki gives this figure (A 3-dimensional k-d tree) to illustrate the process. question How to determine the boundary of the root cell of a k-d ...
2
votes
2answers
45 views

Varying the number of neighbors in nearest-neighbors regression

For nearest-neighbors regression, it is plausible to increase the number of neighbors used to predict $f(x)$ when there are many data points near $x$. What is a good algorithm for varying the number ...
0
votes
1answer
39 views

Has this paper used weighted KNN or not?

Please tell me if you see this paper in the link below has used weighted KNN? because they have used weights as the training and testing samples and no formula written. They don't explain the ...
1
vote
1answer
71 views

Ball Tree and Pseudometrics

The docs for sklearn.neighbors.DistanceMetric state that in order to be used within the BallTree, the distance must be a true metric (i.e. be non-negative, 0 ...
2
votes
0answers
63 views

What does big O mean in KNN optimal weights?

Wiki gives this definition of KNN In pattern recognition, the k-nearest neighbors algorithm (k-NN) is a non-parametric method used for classification and regression. In both cases, the input consists ...
2
votes
1answer
224 views

values passed to user-defined distance function by KNeighborsClassifier is wrong

I have a data-set in which all features are binary and the class of each data-point is also binary. I am trying to use KNearestClassifier with a user-defined distance function as follows: ...
3
votes
3answers
264 views

How to predict the value in KNN?

I am trying to build the KNN algorithm for IRIS dataset. First, I've computed the distance and stored it in 1d array. However, I am really struggling to build the prediction function. Therefore two ...