Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

k-Nearest-Neighbor Classifiers These classifiers are memory-based, and require no model to be fit. Given a query point x0, we find the k training points x(r),r = 1,...,k closest in distance to x0, and then classify using majority vote among the k neighbors.

2
votes
1answer
10 views

KNN parameter tuning with cross validation: score draw

I'm trying to use the KNN method for binary classification. When trying to find the best 'k' parameter (the amount of neighbours that the algorithm looks at) I train a model on my training set and ...
3
votes
1answer
61 views

The violation of triangle inequality in KNN

If the 0<p<1 in the distance metrics, then the triangle inequality is violated. The question as follows Does the violation of this inequality affect the ...
1
vote
0answers
8 views

Voronoi diagrams for kNN

This question is obviously related to Are Voronoi diagrams used in kNN algo implementations?, but I'd like to ask a couple more question than there. I am considering using Voronoi diagram to speed up ...
0
votes
0answers
7 views

Learn mapping function item to item

I'm trying to resolve a problem in which a set of items have to be mapped to another set of items. The mapping has to be one to one and the items have attributes that describe them (e.g. name, ...
0
votes
0answers
15 views

Calculating log-likelihood or BIC of KNN and random forest/boosting models

I am trying to find the BIC of the KNN, random forest and boosting models (for regression, not classification) to use in a combined model that uses Bayesian model averaging to predict a target ...
1
vote
0answers
26 views

K nearest neighbour estimation example

I want to know how the k–Nearest-Neighbor Estimation work. for example i want to classify test sample (0.5, 0) in Unbiased K Nearest Neighbor approximation with k = 3, and Euclidean distance: $d(𝑥,𝑦)...
3
votes
0answers
47 views

Imputation and nested cross-validation

I am planning to do a nested cross-validation analysis using regularized regression. The inner loop will be used for model tuning and the outer loop for model assessment (test set). Because some data ...
1
vote
0answers
23 views

Cross Validation, Variable Definition [closed]

I am working on a 10-fold cross validation problem, and am having an issue with part of my code. Specifically, I'm having a problem with my "for (1 in nfold)" argument, and with the variable length of ...
0
votes
1answer
83 views

Knn Decision boundary

I am new to machine learning and trying to draw decision boundary for k nearest neighbor where k=3. I know that the decision boundary for k=1 would be the perpendicular bisector between two different ...
0
votes
0answers
21 views

can I fill missing values by using target variable?

I have a 3 column data with 2 features and 1 target variable. But the first features (numeric) have a large number of missing values. If I use kNN to fill in the missing values, I am wondering can I ...
1
vote
1answer
51 views

Other distances than euclidean distance in knn [closed]

Suppose I want to fit a k-nearest-neighbour using caret package in R: ...
4
votes
1answer
70 views

Does class balancing introduce bias?

I have a data set that is imbalanced, the prediction rate is not much better than the base line without doing any class balance. I have two classes and I can't collect more data. What I have done: ...
2
votes
2answers
87 views

Does the presence of the outliers affect the 1NN algorithm?

I am working on KNN algorithm. I uploaded and prepared the following dataset. ...
0
votes
1answer
22 views

Similarity between 2 profiles (observations). Is it possible to generate a % similarity?

I have multiple profiles for 10 different people. Each person has been measured for 5 different continuous variables of different magnitudes. So my dataframe is 10x5 where each row represents a person ...
1
vote
1answer
745 views

Training error in KNN classifier when K=1

I got this question in a quiz, it asked what will be the training error for a KNN classifier when K=1. What does training mean for a KNN classifier? My understanding about the KNN classifier was that ...
1
vote
1answer
15 views

Lazy Learning given Submission Files in Competitions

In machine learning settings where you get the "real data" beforehand (e.g. a submission file in competitions like Kaggle), models can be "build around the data" that actually has to be predicted. ...
-1
votes
1answer
18 views

K-means in R: complete case analysis followed by nearest-neighbor assignment for partial data

I have a dataset of 3K observations with only 162 being a complete case. I have read here that it is possible to run knn on the complete cases and then conduct a nearest neighbour assignment for ...
0
votes
0answers
33 views

Why does my kNN model achieve perfect performance on my test set?

I have trained a KNN model using cross validation to minimize a custom loss function. The model clearly overfits the training data, achieving a loss of zero but exhibits variation in 10-fold cross ...
0
votes
0answers
13 views

Intuitive sense of K-nearest neighbor mutual information estimation

I am using the R package Parmigene to estimate the mutual information (MI) between different proteins. The data is spectral counts, which is nonnegative and mostly zero. I want to know what is ...
0
votes
1answer
39 views

Regression kNN model vs. Classification kNN model

I was wondering what is the difference between regression kNN model and classification kNN model. I tried Googling and no success. In presentation from lectures we only have graphs of errors of ...
8
votes
1answer
83 views

Which type of data normalizing should be used with KNN?

I know that there is more than two type of normalizing. For example, 1- Transforming data using a z-score or t-score. This is usually called standardization. 2- Rescaling data to have values ...
5
votes
2answers
189 views

Regression as a way to determine variable importance

At my work, we employ a nearest neighbor algorithm to classify records. Part of this process, of course, includes determining which features to use as auxiliary information in the algorithm. Also, ...
0
votes
1answer
45 views

Can you derive variable importance from a nearest neighbor algorithm?

While the helpful tooltip warned me this question was subjective, I don't think it is. It should be fairly objective to state from a theoretical perspective whether or not you can establish the ...
0
votes
0answers
20 views

Prediction with categorical and continuous Variables

I want to predict the result of a match in a video game (win or loose). It's 5 players against 5 players game, who each plays a specific character. I have : the ID of each character (there are 150 ...
1
vote
0answers
14 views

KNN with categorical values can not predict correctly

I am trying to build a model that given an item, predicts which store it belongs to. I have a data-set of ~250 records which are supposed to be items in different online stores. Each record is ...
0
votes
0answers
19 views

How can I find the k-nearest neighbors for a collection of linear time series data?

I need to figure out how to determine the nearest neighbors of an "optimal" line, as illustrated in a simplified figure, linked below. The blue, orange, green, and purple lines represent the best fit ...
2
votes
1answer
176 views

How to overcome the computational cost of the KNN algorithm?

How to overcome the computational cost of the KNN algorithm when the dataset is large. Bear in mind that I am using my own function for building the knn algorithm in R Is there any manipulation to ...
1
vote
1answer
203 views

Is it possible to compare two different datasets with a different range of values?

I am currently working with the k-Nearest Neighbors (KNN) algorithm. Is it possible to compare two datasets with different ranges of values? In other words, I have one dataset with a range $\in [0,1]...
0
votes
0answers
28 views

kNN prediction using weighted nearest neighbor examples

I've been struggling with this question for about an hour and I can't seem to wrap my head around it. Can someone explain how to use the nearest neighbor examples to make a prediction? This is going ...
1
vote
0answers
41 views

How to select value of k in K-NN when using Transfer Entropy?

I was reading about Transfer Entropy and I came across the estimators used to calculate TE, one of them being the Kraskov Estimator: $ T_{X \rightarrow Y} = \frac{p(Y_{n+1}, Y(k)_{n}, X(l)_{n})*log(...
0
votes
0answers
15 views

KNN: scale data with a concave function to give lower numbers more “weight”?

I am scaling (normalizing) a particular feature (column) in my K-Nearest Neighbors model using the classic min-max (0 to 1) technique. I know I could give the feature more importance than other ...
3
votes
1answer
121 views

Why is N/k the effective number of parameters in k-NN?

For the sake of completeness, $k$-nearest neighbor method classifies a point in space by comparing the average over the labels of $k$ nearest neighbors with $0.5$. The book Elements of Statistical ...
0
votes
0answers
56 views

Nearest Neighbors without fixed dimensions

I got following situation: In a gym there are m trainings-spots (for example a circuit or different trainings-tools). Each trainings-spot has his own unique number to identify it. People training in ...
2
votes
2answers
465 views

Lack of understanding of LOOCV

I am trying to utilize LOOCV in the data partition in R. The idea of LOOCV is to train the model on n-1 set and test the model on the only remaining one set. Then, is to repeat this process n times ...
0
votes
1answer
102 views

Why is my model so accurate when using knn(), where k=1?

I am currently using genomic expression levels, age, and smoking intensity levels to predict the number of days Lung Cancer Patients have to live. I have a small amount of data; 173 patients and 20,...
1
vote
1answer
58 views

Do I need data separation in KNN?

I am trying to use KNN with cancer data. I have split my data into train and test sets. Am I right or I should use LOOCV?
0
votes
1answer
25 views

How to define nearest neighbor search such that it can be optimized using stochastic gradient descent?

Assume that there is a reference two-dimensional array ref and a given vector x. I would like to return the closest vector to <...
2
votes
1answer
193 views

Why effective number of parameters in K nearest neighbor is inversely proportional to K?

ESLII states that effective number of parameters in K nearest neighbor is inversely proportional to K. To get an idea why, note that if the neighborhood were not overlapping, there would be N/K ...
0
votes
0answers
50 views

Why is it that generalization is not guaranteed for 1-nearest neighbors?

I wanted to understand from a statistical learning theory perspective why 1-nearest neighbors doesn't have generalization. I define generalization as empirical risk converging to expected risk as N ...
1
vote
1answer
24 views

k nearest neighbor classification algorithm

I'm currently studying about K nearest neighbour algorithm. I understand the basics of it. The problem I have is I have the below equation given in a slide and do not understand the purpose of it. ...
0
votes
0answers
23 views

Best method to do multiclass classification on a dataset with just 60 samples

I have a dataset with just 60 samples and for each sample I have about 45 predictors. Some of the predictors are derived from others because they represent the percentage of one predictor relative to ...
0
votes
0answers
106 views

Bias decomposition for variance bias tradeoff KNN

i would like to ask a follow up question with regards to the Bias-variance tradeoff decomposition, in particularly for KNN model. This is a question from the conclusion that was given from this thread ...
2
votes
0answers
13 views

Comparing features with respect to nearest neighbors

I have a following problem. There is a dataset and two ways of extracting features from examples (let's name the extracted features $X$, $X'$ where $X_i$, $X'_i$ are feature vectors for $i$th example)...
6
votes
3answers
1k views

Why do we need to fit a k-nearest neighbors classifier?

As I understood, k-NN is a lazy learner algorithm and it doesn't need a training phase. So why do we need to use .fit() with sklearn and what happens when we use it?...
1
vote
1answer
64 views

Curse of dimensionality introducing bias and variance

The Example presented in Elements of Statistical Learning: $Y = f(X) = e^{-8||X||^2}$. X is sampled between $[-1,1]$ is the underlying structure for Y. Authors use k- nearest neighbors. The argument ...
1
vote
1answer
127 views

Difference between identifying outliers using LOF and K-means clustering

I am identifying outliers using K-means and LOF (Local Outlier Factor). Let's say if we are identifying possible outliers using both the techniques, I believe LOF will pick global outliers also as ...
1
vote
0answers
53 views

Knn best accuracy with k = 20

I have a big database with 40k recors and 2 classification classes. In this big database the 76% of records belong to the first class. I've used a 70-30 split partition with stratified sampling, and ...
0
votes
0answers
17 views

How can I fill a feature space to guarantee radial neighbors works in all cases?

I am using a radial neighbors algorithm to make predictions but am running in to trouble because my dataset does not populate the whole input/query space, in this case a hypercube from [-1,1] along ...
1
vote
0answers
204 views

How the kd-tree is used by k-means? [closed]

I read this article of the author Khaled Alsabti, but I don't know how the tree structure is used by k-means. It is suitable for large data?
0
votes
0answers
6 views

Modifying input feature set to incorporate neighboring weekdays effect

I'm using k-NN regression for one of my problems where one of the feature of my input feature set contains the type of weekday (0 for Monday $\ldots$ 6 for Sunday). This has been used to account for ...