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
19 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 ...
-1
votes
1answer
834 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
18 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
18 views

DTW and kNN-DTW time complexity

I have implemented KNN using a custom DTW metric with sci-kit learn and as shown below: ...
3
votes
3answers
832 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 ...
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
33 views
0
votes
1answer
51 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 ...
1
vote
0answers
17 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:
0
votes
1answer
34 views

Which algorithm should I choose and why?

My friend was reading a textbook and had this question: Suppose that you observe $(X_1,Y_1),...,(X_{100}Y_{100})$, which you assume to be i.i.d. copies of a random pair $(X,Y)$ taking values in $\...
3
votes
2answers
205 views

Understanding Learning Curves

I would like to clarify my understanding of learning curves with two example plots below. I am experimenting with small data sets here between 500 and 1500 samples to clarify my understanding. My ...
1
vote
0answers
15 views

Is it possible to use kNN with streaming data

I have built a kNN model using scikit learn that is able to predict a binary outcome very well. The data itself is quite basic, it is simply a 1-D waveform. When feeding the waveform into the model ...
0
votes
1answer
530 views

Random Forest vs K Nearest Neighbor as non linear classifier [closed]

When classes are non-linearly separable, which of the following methods performs better? Choose correct one :- Logistic Regression Random Forest K Nearest Neighbor Classification Linear Regression ...
0
votes
0answers
12 views

what is store in leaf node and split node in Annoy or any approximate nearest neighbor model built using tree?

Im trying to understand the working of annoy and have read the code _make_tree since im not from C++ background im trying hard to figure out the logic of whats stored in leaf node and split node ,you ...
0
votes
0answers
21 views

Does Sklearn's KNeighborsClassifier Map Input to Output If Dimensions Don't Match?

I want to classify a hyperspectral image (Indian Pines data set). The input is of shape (145, 145, 200) = a HSI of 145x145 px with 200 bands. Each one of the 145x145 pixels should be classified to one ...
3
votes
3answers
93 views

Optimal selection of k in K-NN

I am currently reviewing some concepts related to Machine Learning, and I started to wonder about the hyperparameter selection of K-NN classifier. Suppose you need to solve a classification task with ...
0
votes
1answer
110 views

Does shuffling the training data matter in a K Nearest Neighbors Classifier model?

I am new to machine learning and I have a couple of questions about a project. So, I created a classifier using the MNIST data set for a ML project that I was working on. I augmented the data by ...
0
votes
0answers
16 views

Same accuracy on KNN for different distance metrics

I am new to data analysis and I am trying to run a kNN classifier on a lung cancer dataset with multiple attributes. For all k values I tasted (1 to 10), I obtain the same accuracy when using either ...
4
votes
1answer
123 views

Is there an algorithm that imputes missing values based on n nearest columns? (KNN hybrid)

I have a dataset of 70 columns that have missing values. Each column has a few columns (3-5) that it is significantly more correlated than the others but each column's correlated columns are very ...
0
votes
0answers
129 views

Estimate eps value in DBSCAN using KNN algorithm

I would like to estimate the best eps value for the DBSCAN algorithm on this dataset by following this set of rules: Set a minPts: 10 Compute the reachability distance of the 10-th nearest neighbour ...
0
votes
2answers
34 views

Impossible to increase model accuracy [closed]

I'm building binary classification models on my company's dataset. The problem I'm having is that I haven't been able to increase the accuracy of my models. I have trained, tuned, cross validated ...
2
votes
3answers
11k views

Features selection in KNN

I have a naive question about using the K Nearest Neighbor algorithm: is feature selection more important in KNN than in other algorithms? If a particular feature is not predictive in a neural ...
0
votes
1answer
191 views

Combine K-nearest neighbor with categorical embedding

I've tried a few ways to do my multi-class classification. For categorical data, I used the embedding technique with Tensorflow, which moves the entity closer with its similarity. This technique ...
-1
votes
1answer
51 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 ...
11
votes
1answer
628 views

Learning with Positive labels only

I have ~7 million rows of customer data (~500 sparse attributes) A million out of them have opted in to a new service. How do I use this signal to predict which of the remaining customers are likely ...
1
vote
1answer
79 views

Standardization on training and split data

I am confused on which of the following should be used for standardization: method 1: fit transforming training data and only transforming test data ...
0
votes
1answer
383 views

Why does the overfitting decreases if we choose K to be large in K-nearest neighbors?

I am studying machine learning and I am focusing on K-nearest neighbors . I have understood the algorithm, but I have still a doubt, which is on how to choose the K for the number of neighbors. I ...
1
vote
0answers
14 views

Redo preprocess on unknown row

I'm trying to write a script to get the most similar rows in a certain dataframe, based on a single row. Using scikit-learn The method I need is ...
2
votes
0answers
80 views

Classification and clustering of Time series data of temperature

I have a time series recorded data of temperature. This is what my data looks like: The change in data represents specific event or a class which I would like to detect when new incoming data. ...
4
votes
1answer
87 views

KNN Regression: Distance function and/or vector representation for datetime features

Context: Trying to forecast some sort of consumption value (e.g. water) using datetime features and exogenous variables (like temperature). Take some datetime features like week days (...
0
votes
1answer
402 views

Calculating distance between data points when there are more than 3 features in KNN algorithm

I've been reading about K-nearest neighbors algorithm and want to clarify few things. If we have 2 features we could simply plot it on 2-d plane and calculate distance by using euclidean distance or ...
0
votes
1answer
44 views

Logic behind the Statement on Non-Parametric models

I am currently reading 'Mastering Machine Learning with scikit-learn', 2E, by Packt. In Lazy Learning and Non-Parametric models topic in Chapter 3- Classification and Regression with k-Nearest ...
3
votes
2answers
201 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 ...
0
votes
0answers
29 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 ...
1
vote
2answers
57 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 ...
0
votes
2answers
946 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? ...
2
votes
3answers
86 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 ...
1
vote
2answers
281 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 ...
1
vote
1answer
466 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 ...
4
votes
1answer
810 views

K Nearest Neighbour with different distance matrix to each datapoint

I'm wondering if there is library support in python (such as sklearn) for doing KNN on a data set that has a custom distance matrix (positive definite) for each data point (x is a query point, $x_i$ ...
1
vote
1answer
2k 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
1answer
141 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
34 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
2answers
245 views

Visualizing Decision Tree of K-Nearest-Neighbours classifier

I'm using Sklearn's KNN to build a classifier and was wondering if there is any way to visualize the decision tree that the algorithm builds. Maybe something of this fashion
0
votes
1answer
925 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 ...
6
votes
1answer
120 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
0answers
36 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 ...
1
vote
0answers
93 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 ...
1
vote
1answer
32 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, ...