I am attempting to train a classifier to predict different prices for an item in different suburbs. I have several features, two of which are a latitude and longitude for the centroid of the suburb.

I am attempting to train the model to classify the price of an item in a bin of $10 size. The geospatial element will definitely affect the price of the item, however the training data I have will have gaps in it (i.e. I don't have prices for all suburbs).

What is the best way to engineer a feature that will include this geospatial information and be able to fill in the gaps in the training/test data?

So far I have tried creating new features for the bearing and distance from the capital city which seemed to work okay, as well as binning the latitude and longitude which performs worse than the bearing/distance. I did consider using a geohash, however I think that this will be too complex a feature for a classifier to understand.

  • $\begingroup$ Interestingly combining the binning and the bearing/distance has increased my overall accuracy to 0.82. $\endgroup$
    – Aidos
    Aug 13, 2015 at 7:54
  • $\begingroup$ Is the price your target variable or a feature ? $\endgroup$ Aug 13, 2015 at 9:14
  • $\begingroup$ Price is my label I am attempting to classify. In my training data I have binned it into $50 buckets $\endgroup$
    – Aidos
    Aug 13, 2015 at 9:17
  • $\begingroup$ The geospatial element definitely has an impact on the prices that are returned - so I can't ignore it at all. $\endgroup$
    – Aidos
    Aug 13, 2015 at 10:29

1 Answer 1


If this is a U.S. model you can try County (FIPS) codes, which are coarser-grained areas than ZIP codes (there can be many ZIP codes in a county). If bearing and distance worked for you, this should also work. Your classifier would need to handle categorical data. In R, this is pretty easy to do if you already have a ZIP code:

my_dataframe['fips']<-zip_codes$fips[match(my_dataframe$zip, zip_codes$zip)]

This assumes you already have a dataframe called my_dataframe with ZIP codes as a column named 'zip'.

As a bonus you can use the choroplethr package to create a nice visualization of some scalar value, for example, your item price:


county_choropleth(df_to_plot, title='price by location')

enter image description here

  • $\begingroup$ Thats a good idea - unfortunately I am in Australia, but I will check the Australian Bureau of Statistics to see if they have something similar (from memory a Census Collection Area might be workable). $\endgroup$
    – Aidos
    Aug 24, 2015 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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