Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
14 views
1
vote
1answer
31 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
19 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: ...
0
votes
1answer
37 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: ...
0
votes
1answer
41 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
27 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
53 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 ...
0
votes
0answers
14 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
27 views

How to evaluate unsupervised KNN?

I'm creating a recommender system using an unsupervised nearest neighbors model to suggest similar publishers for a given publisher, advertiser combination. I'm wondering how to evaluate the model I ...
0
votes
0answers
13 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
34 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
24 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
39 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
48 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 ...
2
votes
1answer
76 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: ...
1
vote
1answer
68 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 ...
3
votes
1answer
34 views

Is the distance in Nearest Neighbors a good measure of similarity?

Let's train a Nearest Neighbor model with just one sample in it: In [48]: nn = NearestNeighbors().fit([[0, 1, 0, 0]]) So this one sample has just one significant ...
0
votes
1answer
47 views

Machine Learning algorithm for detecting anomalies in large sets of events

Let's start with the following hypothetical preconditions: There is traffic: normal and anomaly. Each traffic sample contains a list of events (of variable size) Events happen in order, the possible ...
2
votes
1answer
38 views

Item-based recommender using K-NN

I'm trying to build an item-based recommender using k-nn. I have a list of items, all of which have some properties (features) in common. ...
1
vote
1answer
53 views

What is the Value of X in KNN and Why? [duplicate]

I have a dataset of 25 instances these instances are divided into 2 classes Green Circles and Blue Squares data distributed as this graph I want to predict X's class based on "Likelihood Weighted ...
1
vote
1answer
124 views

logic behind weighted KNN

I am reading about KNN So I made another example to make things clearer In this example (Image attached) You can see there are in total 5 Greed Circles and 20 Blue Squares by standard KNN (k=3) , ...
0
votes
1answer
24 views

adding a supervizing process during knn process

I try to improve my knn regression process (I use sklearn / python, but it doesn't matter). Because I can have a scientific point of view on my data, I would like to improve my results. I give you an ...
0
votes
1answer
23 views

learning a distance metric from the output of a knn output

Suppose that someone has trained a nearest-neighbor algorithm based on some unknown metric. I have a large dataset of $N$ observations, and $P$ features. For each observation I am given $K$ indices ...
1
vote
1answer
74 views

KNN RandomizedSearchCV typerror

While trying to study a binary classification problem with KNN and trying to tune the parameters of the model I'm getting a typerror that I quite don't understand. Is a parameter missing or something? ...
2
votes
1answer
43 views

Mapping of categorical features into binary indicator features

I am currently reading an introductory machine learning book by Daumé (ch. 03, p. 30) and when discussing the mapping of categorical features with "n" possible values into "n" binary indicator ...
0
votes
1answer
23 views

Does it make sense to use KNN to target ticket buyers for arts events?

I work for a medium-sized non-profit. We have a database with approximately 40,000 profiles of folks (mostly patrons). For each show a patron attends, we add an attribute that indicated that they're ...
1
vote
4answers
659 views

How to save a knn model?

I need to save the results of a fit of the SKlearn NearestNeighbors model: knn = NearestNeighbors(10) knn.fit(my_data) How do you save to disk the traied ...
2
votes
1answer
63 views

Coordinate System's influence on $L$ distances (Manhattan and Euclidean)

I don't understand this picture, which says if we change the coordinate system, we would have the same result for $L_2$ distance, whereas, our result would differ for $L_1$ distance. What does it ...
0
votes
0answers
49 views

How do I avoid time leakage in my KNN model?

I am building a KNN model to predict housing prices. I'll go through my data and my model and then my problem. Data - ...
2
votes
1answer
66 views

K-Nearest Neighbours algorithm explanation needed

I need some explanation for K-Nearest Neighbors algorithm. Why is the training process needed in KNN algorithm? In regression models the training process means to find optimum parameters for a ...
0
votes
1answer
39 views

Normalization(minmax) gives me worse results than before in KNN, follow up actions?

Hello I'm studying a classification problem with KNN right now. I have many numeric features that I normalized with MinMaxScaler, I also got some OHE categorical features that not seem to cause the ...
1
vote
1answer
45 views

Can `k=1` be a good choice for K neighbors classification?

Running sklearn.KNeighborsClassifier() on Kaggle's Leaf Classification sample (set of 99 species, 10 specimen each), with defaults kNN parameters and a grid search ...
3
votes
1answer
200 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$ ...
3
votes
0answers
49 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 ...
1
vote
2answers
180 views

Choosing k value in KNN classifier?

I'm working on classification problem and decided to use KNN classifier for the problem. so if k=131 gave me auc of 0.689 and k=71 gave me auc of 0.682 what should be my ideal k? Does choosing ...
0
votes
1answer
26 views

Date transformation for KNN to get distance [duplicate]

I have data set with date features like 01/01/2019 and I would like to use KNN. However, I cannot find a good transformation for dates that has a meaningful distance result for the last feature. For ...
0
votes
2answers
71 views

Date transformation for KNN

I have data set with date features like 01/01/2019 and I would like to use KNN. However, I cannot find a good transformation for dates that has a meaningful ...
6
votes
1answer
98 views

How to decide how many n_neighbors to consider while implementing LocalOutlierFactor?

I have a data set with rows: 134000 and columns: 200. I am trying to identify the outliers in data set using LocalOutlierFactor from scikit-learn. Although I ...
1
vote
0answers
274 views

Training anomaly detection on text string [closed]

I have text string stored in a column, resulting after pre-processing of web traffic data. Now I want to apply anomaly detection on it and for that purpose I applied ...
0
votes
0answers
20 views

Neighbourhood based approach on implicit feedback datasets

Is it possible to use a neighbourhood-based approach on implicit feedback dataset? I have a dataset with information about how many times a certain item was viewed by a particular user. I know that MF ...
0
votes
0answers
12 views

approximate k-nearest neighbours with LSH

I m studying LSH and one question of my book say that with LSH we can reproduce an approximate K-NN algorithm. I m thinking on, and I just have this idea: Hash all element of the data Check the ...
1
vote
1answer
432 views

Scaling label encoded values for Linear Algorithms

I have encoded categorical variables to numerical values. As we know that for feeding values to Linear Algorithms like SVM or KNN, we scale the values for columns having large variations. I have ...
3
votes
3answers
57 views

A metric between trees

I have certain tree structures. I am not an expert in machine learning. As I would with take KNN, I would calculate distances via metric function and a new data point and the points from the training ...
0
votes
1answer
319 views

Why do I not get 100% Accuracy with KNN with $K=1$

I am playing with KNN on the Iris Dataset I expected to get 100% accuracy with $K=1$ since every point should predict itself based on the Voronoi volume around it created by the KNN algorithm. ...
3
votes
2answers
88 views

Regression for discrete values?

Im a noob in ml / statistical algorithm, but I do have worked with simple classifiers and regression I like some opinions if I am going the right way, given my limited knowledge My problem is ...
1
vote
0answers
245 views

ValueError: operands could not be broadcast together with shapes (140,) (10230,)

I wrote this code for emotion recognition using EEG data. I am performing feature extraction by finding mean and standard deviation and performing classification using Knn algorithm. I am getting this ...
0
votes
1answer
279 views

How to handle date data for Knn?

I'm working on a project about predicting kickstarter project success(classification) and my dataset has many columns that could be used as features such as : state_changed_at, launched_at, ...
2
votes
1answer
3k views

How Does Weighted KNN Work?

I am reading notes on using weights for KNN and I came across an example that I don't really understand. Suppose we have K = 7 and we obtain the following: Decision set = {A, A, A, A, B, B, B} If ...
0
votes
2answers
3k 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 ...