All Questions

Tagged with
Filter by
Sorted by
Tagged with
11 votes
3 answers
14k views

How to convert distance into probability?

Сan anyone shine a light to my matlab program? I have data from two sensors and i'm doing a kNN classification for each of them separately. In both cases training set looks like a set of vectors of 42 ...
niko_dry's user avatar
  • 111
7 votes
1 answer
802 views

Euclidean distance, different results between Scipy, pure Python, and Java

I was playing around with different implementations of the Euclidean distance metric and I noticed that I get different results for Scipy, pure Python, and Java. Here's how I compute the distance ...
Silas Berger's user avatar
3 votes
2 answers
3k views

5 nearest neighbors based on given distance in r

I have the following dataset: id x y age 1 1745353 930284.1 30 2 1745317 930343.4 23 3 1745201 930433.9 10 4 1745351 930309.4 5 5 1745342 930335.2 2 6 ...
user2797174's user avatar
2 votes
1 answer
5k views

Euclidean Distance between Scipy Sparse Matrix and Sparse Vector

I am working on a KNN algorithm for a university assignment and at the moment I'm working on finding the Euclidean distance between each of the training vectors stored as a Scipy lil_matrix (due to ...
Lincoln's user avatar
  • 85
2 votes
4 answers
3k views

Euclidean distance between np arrays

I have two numpy arrays a and b: a and b are the same dimensions, a could be a different size than b. For instance: a = [[1,2], ..., [5,7]] b = [ [3,8], [4,7], ... [9,15] ] Is there an easy ...
Mike El Jackson's user avatar
2 votes
2 answers
596 views

Optimize K-Nearest Neighbors Algorithm on 50 variables x 100k row dataset

I want to optimize a piece of code that helps me to calculate a nearest neighbour for every item in a given dataset with 100k rows. The dataset contains 50 variable-columns, which helps to describe ...
d_-'s user avatar
  • 1,441
2 votes
2 answers
3k views

Distance measure for categorical attributes for k-Nearest Neighbor

For my class project, I am working on the Kaggle competition - Don't get kicked The project is to classify test data as good/bad buy for cars. There are 34 features and the data is highly skewed. I ...
Jatin Ganhotra's user avatar
1 vote
1 answer
461 views

How to adjust this code to also Return second and third "Nearest Neighbors"?

Based on this code from calculating average distance of nearest neighbours in pandas dataframe, how can I adjust it so that it returns the second and third nearest neighbor into new columns? (Or ...
user avatar
1 vote
2 answers
565 views

distance measure used to calculate k nearest neighbour

I am reading about k nearest neighbour, and the distance measure given in the example is as below. It says Ri is the range of the i-th component. I am confused about which distance measure is used ...
user4046073's user avatar
1 vote
1 answer
1k views

Finding most similar items by euclidean and cosine

How do I go about finding similarities in R? In particular, the similarity metrics I care most about are cosine and a KNN-# value. I guess the key aspect of this is so that the data comes out in a ...
runningbirds's user avatar
  • 6,425
1 vote
1 answer
24 views

How to get the index of multiple mininum values in a column?

I'm trying to get the k minimun values of each column on a dataframe. however I am unable to get the indices. I have a dataframe that contains the distances between data called ddist. I want to select ...
Regina Briseño's user avatar
1 vote
1 answer
551 views

Find euclidean distance between rows of two huge CSR matrices

I have two sparse martrices, A and B. A is 120000*5000 and B is 30000*5000. I need to find the euclidean distances between each row in B with all rows of A and then find the 5 rows in A with the ...
peykaf's user avatar
  • 79
1 vote
0 answers
54 views

Manual kth Nearest Neighbor Euclidean Distance

I have to modify the following code in order to use 1, 3, and 5 neighbors and print the accuracy of each one. I can not use the sklearn library KNeighborsClassifier so I am stuck because I don't know ...
Jaime's user avatar
  • 25
1 vote
2 answers
1k views

How K-NN Algorithms work with same distance in rapidminer?

Actually I already asked in rapidminer forum, but no one has given an answer yet.. https://community.rapidminer.com/discussion/55963/how-k-nn-algorithms-work-with-same-distance-in-rapidminer#latest I ...
AdeMuchlis's user avatar
1 vote
0 answers
117 views

the implementation of lazy multi label classifiers in Mulan

I want to use k nearest neighbor for multi label classification. there are some classifiers based on knn which are implemented in mulan library, or are written in C or Matlab such as MLKNN. when I ...
niloofar's user avatar
1 vote
1 answer
204 views

K-nn to predict the class of the data using Euclidean distance in R

I would like to apply k-nn on a learning set to predict the class of the data using the Euclidean distance. I am finding some difficulties with implementing this method
Elie Daher's user avatar
1 vote
1 answer
2k views

How to define weights for KNN?

I want to identify a set of weights for the distance measure in KNN method. I read through the MATLAB help and I found that there are functions for inverse or squared inverse (w.r.t the distances) ...
IRIS's user avatar
  • 23
0 votes
1 answer
705 views

computing the euclidean distance for KNN

I've been seeing a lot of examples of computing euclidean distance for KNN but non for sentiment classification. For example I have a sentence "a very close game" How do I compute the euclidean ...
xx4xx4's user avatar
  • 45
0 votes
1 answer
2k views

k-Nearest Neighbour Algorithm in verilog

Im planning to do KNN's verilog implementation. But the problem is the euclidean distance measurement term associated with KNN,since it needs Subtraction,squaring,adding. I think,the code will become ...
Viz's user avatar
  • 11
0 votes
0 answers
56 views

Calculate Euclidean distance in pyspark

I’m trying to build a lookalike in pyspark. Basically finding a closest customer from control dataset(2M size) for test population(20k size) I have created vectors for both datasets Now I want to find ...
revati's user avatar
  • 1
0 votes
0 answers
336 views

Applying weights to KNN dimensions

When doing a KNN searches in ES/OS it seems to be recommended to normalize the data in the knn vectors to prevent single dimensions from over powering the the final scoring. In my current example I ...
TGH's user avatar
  • 38.9k
0 votes
0 answers
161 views

Create graph from euclidean distances using KNN

import numpy as np import pandas as pd import networkx as nx from scipy.spatial.distance import cdist from sklearn.neighbors import NearestNeighbors Given the following array: A = np.array([[1.25,1.1,...
8-Bit Borges's user avatar
  • 9,864
0 votes
3 answers
2k views

What is the Most Efficient Way to Compute the (euclidean) Distance of the Nearest Neighbor in a List of (x,y,z) points?

What is the most efficient way compute (euclidean) distance of the nearest neighbor for each point in an array? I have a list of 100k (X,Y,Z) points and I would like to compute a list of nearest ...
Cole Pierson's user avatar
0 votes
0 answers
1k views

How to count kNN with Manhattan distance in R?

In program distance is Euclidean (which is by default). How to change it to Manhattan? Code: wdbc <- read.table(file.choose(), sep=",") View(wdbc) wdbc <- wdbc[, -1] data_norm <- ...
Ernesta Petraitytė's user avatar
0 votes
0 answers
313 views

Errors using R to write KNN from scratch

I'm trying to create the knn formula from scratch in R. This is the code I have so far... train.df <- read.csv("SchoolkidsTrain.csv", header = TRUE, sep = ',') test.df <- read.csv("...
Stacey K.'s user avatar
-1 votes
1 answer
6k views

K-Nearest Neighbor Implementation for Strings (Unstructured data) in Java

I'm looking for implementation for K-Nearest Neighbor algorithm in Java for unstructured data. I found many implementation for numeric data, however how I can implement it and calculate the Euclidean ...
F. Fo's user avatar
  • 123