How to handle Lat/Lon features in a model?

machine_learning
feature_engineering

#1

How could we handle latitudes and longitudes variables in our model?
Ideas?


#2

Hi @abhishek.gitam

You can refer the following threads,


#3

I worked on a model that I wanted to include a location indicator and had longitude and latitude, however that caused issues with the model using them as numeric values - not a desired interpretation. What I did was used a regional indicator and for the project I was working on I used the US Census regions: https://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf I took the state and determined which region it fell in (West, Midwest, Northeast, or South). Each region was a separate indicator (four indicators) and I set them to 0 or 1.

Below is R code showing the indicators:
dfMaster$RegWest <- 0
dfMaster$RegWest <- replace(dfMaster$RegWest, dfMaster$STATE_ABR == “WA” || dfMaster$STATE_ABR == “OR” ||
dfMaster$STATE_ABR == “ID” || dfMaster$STATE_ABR == “MT” ||
dfMaster$STATE_ABR == “WY” || dfMaster$STATE_ABR == “NV” ||
dfMaster$STATE_ABR == “CA” || dfMaster$STATE_ABR == “UT” ||
dfMaster$STATE_ABR == “CO” || dfMaster$STATE_ABR == “AZ” ||
dfMaster$STATE_ABR == “NM” || dfMaster$STATE_ABR == “AK” ||
dfMaster$STATE_ABR == “HI”,1)

dfMaster$RegMidWest <- 0
dfMaster$RegMidWest <- replace(dfMaster$RegMidWest, dfMaster$STATE_ABR == “ND” || dfMaster$STATE_ABR == “SD” ||
dfMaster$STATE_ABR == “MN” || dfMaster$STATE_ABR == “WI” ||
dfMaster$STATE_ABR == “NE” || dfMaster$STATE_ABR == “KS” ||
dfMaster$STATE_ABR == “IA” || dfMaster$STATE_ABR == “MO” ||
dfMaster$STATE_ABR == “IL” || dfMaster$STATE_ABR == “IN” ||
dfMaster$STATE_ABR == “MI” || dfMaster$STATE_ABR == “OH”,1)

dfMaster$RegNorthEast <- 0
dfMaster$RegNorthEast <- replace(dfMaster$RegNorthEast, dfMaster$STATE_ABR == “ME” || dfMaster$STATE_ABR == “VT” ||
dfMaster$STATE_ABR == “NH” || dfMaster$STATE_ABR == “MA” ||
dfMaster$STATE_ABR == “RI” || dfMaster$STATE_ABR == “CT” ||
dfMaster$STATE_ABR == “NY” || dfMaster$STATE_ABR == “NJ” ||
dfMaster$STATE_ABR == “PA”,1)

dfMaster$RegSouth <- 0
dfMaster$RegSouth <- replace(dfMaster$RegSouth, dfMaster$STATE_ABR == “DE” || dfMaster$STATE_ABR == “MD” ||
dfMaster$STATE_ABR == “DC” || dfMaster$STATE_ABR == “VA” ||
dfMaster$STATE_ABR == “WV” || dfMaster$STATE_ABR == “KY” ||
dfMaster$STATE_ABR == “NC” || dfMaster$STATE_ABR == “SC” ||
dfMaster$STATE_ABR == “TN” || dfMaster$STATE_ABR == “GA” ||
dfMaster$STATE_ABR == “FL” || dfMaster$STATE_ABR == “AL” ||
dfMaster$STATE_ABR == “MS” || dfMaster$STATE_ABR == “LA” ||
dfMaster$STATE_ABR == “AR” || dfMaster$STATE_ABR == “OK” ||
dfMaster$STATE_ABR == “TX”,1)