Euclidean distance calculation for large data sets

I need to calculate the Euclidean distance between train and test data. the total length of the train data is 1389, and for the test data it is 364. This is mainly data from handwritten postal codes on envelopes from US mail, downloaded from the Statistical Learning Elements website .

I start and just read the data in an R package. I can’t start calculating the distance between the train and test data. Can someone help me to give me an idea on how to create a loop for this data?

I would be thankful.

+3
source share
1 answer

rdist fields. dist stats , :

train.data <- matrix(runif(1389*2), ncol = 2)
test.data  <- matrix(runif(364*2),  ncol = 2)

library(fields)
distances <- rdist(train.data, test.data)
dim(distances)
# [1] 1389  364
+6

All Articles