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")
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(
model_knn <- train(X, Y, method='knn', tuneLength=5, trControl=ctrl)
model_rf <- train(
X, Y, method='rf',
The caret package in R makes it easy to compare regression models (scikit-learn has similar tools):
knn = model_knn,
rf = model_rf
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.