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
10 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
14 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
36 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
30 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
60 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
38 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
37 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
29 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
21 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
10 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
18 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
32 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
27 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
60 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
44 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 ...
1
vote
1answer
143 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
16 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
21 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
172 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
45 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
236 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
32 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
318 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
33 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
45 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
42 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
32 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
68 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
57 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
165 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
183 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
57 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
51 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
46 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
55 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
257 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
79 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 ...
1
vote
2answers
47 views

Reverse engineering a distance metric from the output of a k-NN

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
137 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? ...
5
votes
1answer
77 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 ...
-1
votes
1answer
25 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
2k 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
149 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
57 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
99 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 ...