I have lat/lon and property values for households in a particular region.

Lat     Lon      value
32.2  -98.22    120000

Now I have new data of the same region, but just have lat/log values. I want to estimate the household values using some nearest neighbor algorithm. Which is the best algorithm for this purpose? I am currently working with KDTrees from Scipy. Thanks

  • $\begingroup$ Kriging seems like the natural choice. $\endgroup$
    – Sycorax
    Jul 14, 2015 at 16:40
  • 2
    $\begingroup$ What's the purpose of this prediction? $\endgroup$
    – Aksakal
    Mar 2, 2016 at 22:06
  • $\begingroup$ Estimating household value of houses for which I dont have information $\endgroup$
    – icm
    Mar 4, 2016 at 14:47

2 Answers 2


Kriging will work, since at it's core it is similar to IDW in that it uses surrounding measured values to predict values at an unknown location, with a few perks of being a geostatistical interpolator (including producing semivariograms to help the user understand spatial auto-correlation). I'd also recommend looking into IDW and other interpolation methods to see what suits your needs best. The better spatial coverage your sample points have the better your result will be. If you have access to a GIS package like ArcGIS, through your university this process is straightforward. If not, QGIS is a very capable open source solution. As pointed out below, achieving greater accuracy in your Lat/Long fields would be highly beneficial despite your interpolation method of choice.

  • $\begingroup$ Can you add a couple sentences about why you think kriging will work? There are assumptions behind this method. $\endgroup$
    – AdamO
    Jul 14, 2015 at 18:21
  • $\begingroup$ Hedonic pricing models developing using kriging have worked, but they show that over regions the size of the imprecision in the coordinates of the question (a latitude given only to $0.1$ degrees is uncertain by over $5$ kilometers north and south!) the stationarity assumption will be difficult to justify. At a minimum, covariates would be needed. BTW, it's hard to tell what you mean by "at its core," because kriging is substantially different from IDW in almost any aspect that matters. $\endgroup$
    – whuber
    Jul 14, 2015 at 18:52
  • $\begingroup$ What is IDW? ............................... $\endgroup$ Mar 2, 2016 at 22:20
  • $\begingroup$ IDW stands for Inverse distance weighting $\endgroup$ Feb 28, 2017 at 2:06

knn is probably a good, simple approach, but tree-based models may work too, and would let you easily incorporate other data (e.g. number of rooms, etc.).

Here's a simple example (in R, but all the code would be pretty easy to port to scikit-learn). First, we make a spatially correlated dataset:

N <- 10000
dat <- data.frame(
  lat = rnorm(N, mean=32.2, sd=10),
  lon = rnorm(N, mean=-98.22, sd=10)
g.dummy <- gstat(
  model=vgm(psill=0.025, range=5, model='Exp'),
dat$value <- 120000 ^ predict(g.dummy, newdata=dat, nsim=1)$sim1
dat$log_value <- log10(dat$value)
ggplot(dat, aes(x=lat, y=lon, color=log_value)) +
  geom_point() + theme_bw() + scale_colour_gradient(low="blue", high="orange")

spatial data

Then we can use both a knn and a random forest (with lat/lon as inputs) to predict values:

X <- dat[,c('lat', 'lon')]
Y <- dat[,'log_value']
ctrl <- trainControl(
  method='cv', number=10,
  index=createFolds(Y, 10))
model_knn <- train(X, Y, method='knn', tuneLength=5, trControl=ctrl)
model_rf <- train(
  X, Y, method='rf',
  tuneGrid=data.frame(mtry=2), trControl=ctrl)

The caret package in R makes it easy to compare regression models (scikit-learn has similar tools):

  knn = model_knn,
  rf = model_rf
)), metric='RMSE')

model compare

For this specific dataset, the knn model (with k = 5) is a bit more accurate, but the random forest is close. If you have other variables you could include in your model, the random forest will probably have an easier time incorporating non-spatial variables.

There are of course many other kinds of models aimed specifically at solving this sort of problem. No matter the model you choose, you should cross-validated it and compare it's out of sample predictions to other models.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.