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
1answer
27 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 ...
1
vote
1answer
39 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 ...
2
votes
2answers
57 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?
4
votes
1answer
97 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
30 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
15 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
69 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
19 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
24 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
34 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
35 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
528 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
32 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
36 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
13 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
48 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
61 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
632 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
17 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
17 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 ...
1
vote
0answers
16 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
138 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
13 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
320 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
18 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
86 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
73 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 ...
0
votes
0answers
107 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
33 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 ...
0
votes
1answer
153 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 ...
11
votes
1answer
597 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 ...
3
votes
2answers
54 views

Missing value Imputation in dataset

I have two separate files for Testing and Training. In the training data, I am dropping rows that contain too many missing values . But , In the test data , I cannot afford to drop the rows so I have ...
1
vote
1answer
59 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
164 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 ...
3
votes
0answers
46 views

Could my AI classifier be extended to categorical data? [closed]

I created a new AI classifier. Physics Based Classifier
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
67 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. ...
0
votes
2answers
126 views

sklearn KNN fit throws out error : value too large for dtype('float64')

I have cleaned the data from nan values and infinite values, the only feature which has a large float is the column 8 (it's a sum) I have no Idea how to fix this last error, I tried all previous ...
4
votes
1answer
84 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
331 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
41 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 ...
2
votes
2answers
75 views

Using KNN to categorise inventory (physical stock items) - is it the best way?

I'm working on a machine learning problem involving inventory (i.e. physical retail stock), however through the cleaning (outlier removal) process some of the items (via their corresponding ...
1
vote
2answers
283 views

KNN Imputation utilize mean or mode?

In my current project, I am doing KNN imputation with K = 5 and I am using sklearn.impute.KNNImputer. I have a mix of continuous and nominal variables(encoded as 0/1 or ordinal ones that have been ...
0
votes
0answers
23 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 ...