63

K-means is not the most appropriate algorithm here. The reason is that k-means is designed to minimize variance. This is, of course, appearling from a statistical and signal procssing point of view, but your data is not "linear". Since your data is in latitude, longitude format, you should use an algorithm that can handle arbitrary distance ...


12

K-means should be right in this case. Since k-means tries to group based solely on euclidean distance between objects you will get back clusters of locations that are close to each other. To find the optimal number of clusters you can try making an 'elbow' plot of the within group sum of square distance. This may be helpful


11

Looks like https://github.com/pbugnion/gmaps is what you're looking for. You can do things like this with it:


9

GPS coordinates can be directly converted to a geohash. Geohash divides the Earth into "buckets" of different size based on the number of digits (short Geohash codes create big areas and longer codes for smaller areas). Geohash is an adjustable precision clustering method.


8

I am probably very late with my answer, but if you are still dealing with geo clustering, you may find this study interesting. It deals with comparison of two fairly different approaches to classifying geographic data: K-means clustering and latent class growth modeling. One of the images from the study: The authors concluded that the end results were ...


6

You can use HDBSCAN for this. The python package has support for haversine distance which will properly compute distances between lat/lon points. As the docs mention, you will need to convert your points to radians first for this to work. The following psuedocode should do the trick: points = np.array([[lat1, lon1], [lat2, lon2], ...]) rads = np.radians(...


5

You cannot use them directly, as it is unlikely there is a true linear relationship unless you're looking to predict "how far east or north" someone is. As mentioned in the comments, you need to convert them into zones. If you wanted to keep it really simple, you could use a kNN clustering algorithm with a low number of potential clusters and then assign ...


4

I suggest to calculate the Haversine distance between two points, and fit a linear regression to find the relation between the Haversine distance and the trip duration. So your regression will be $duration_t = timestamp_t - timestamp_{t-1} = \alpha + \beta*d(point_t,point_{t-1})$ Where $d$ is the Haversine distance. $point_t$ is a lat/long pair at time $t$. ...


3

If you are predicting crime rates in a certain region, we may use clustering to deduce useful information. In clustering, basically, we will try to group similar data points together and treat them as a single class. We can understand this with an instance. We have various points ( Latitude and Longitude ) and each of them represents a certain type of crime....


3

There are a number of APIs for OpenStreetmap, e.g. via html request: https://nominatim.openstreetmap.org/search?q=pleikartsförsterstrasse,%20heidelberg&format=json&polygon=1&addressdetails=1 A json is returned. You can easily access the type of information you need.


2

To predict timestamps from two predictor variables longitude and latitude, you want to train a multiple linear regression model of the form $$Timestamp = \alpha + \beta_0 \cdot Longitude + \beta_1 \cdot Latitude.$$ Given a new latitude-longitude pair of you destination, you can then compute the ETA. Spark's LinearRegressionWithSGD model should be able to ...


2

Take the taxi routes and combine them with civilian car routes to form a data set for classification. Using a map (say, from Google) break down each route into a sequence of roads segments, from intersection to intersection. If you only have GPS traces this will involve spatio-temporal segmentation. (Intersections/terminuses are places where cars go but ...


2

There are many such approaches, for example spatial autocorrelation, Lisa, etc. In the clustering domain, GDBSCAN is a generalization of DBSCAN where you could easily define neighbors as points being within a certain distance and having a similar price. Nevertheless it is probably a good idea to look into actual geostatistics and beyond the limitations of ...


2

You could do whatever your heart desire, but unless your model predicts the temperature or time-difference, I cannot come up with any other target variable that depends solely on the coordinates. What you probably want to do, is use an external data source and enrich your data with Country / Zip code / climate / other geographic features that will help your ...


2

In the past what better worked for me was encoding the location as a categorical variable with: Geohash python And then target encoding to change to a numerical feature: Target Encoding from category_encoders It arises the problem of the granularity, but it can be modified: You can specify an arbitrary precision when encoding. The precision determines ...


1

This blog article might be a good starting point. From what you described and depending on your data, semantic segmentation might be overkill and classification will suffice. Either way, the first step will be to get your hands on training data. If you do not have labels already, this might mean that you have to sit down for a while an label a bunch of ...


1

This is to get whether the incident_zip is in the list of zip code. df.isin({'incident_zip' : zip_code_list) If you have a zip code borough mapping in the form of dict. You can do df['borough'].map(zip_to_borough) For pandas dataframe never iterate say by rows unless as last resort because the performance will be terrible. You can speed these operation ...


1

There is a way that is not optimum for performance, but clear to read and understand. Also, you can use more complex logic and update with different values as you wish. def myfunc(row): if row['incident_zip'] in [this is a list of zip codes]: return new_value else: return row['borough'] #return old value data['borough'] = data.apply(...


1

If what you have are places names and you want to get its coordinates, you can use some library, for example, geopandas. It has the geocoding feature, which converts place names to locations on Earth. You can also use the Google maps Geocoding API. There are many more API services which solve this problem, but those two should get you started. Hope this ...


1

Data needs to be modeled as a graph to use graph algorithms. Longitude and latitude can not be modeled directly as nodes, thus graph algorithms can not be directly applied. The biggest reason is that nodes in a graph have no notion of distance, just weight. Pairs of longitude and latitude have an inherent notion of distance. There are at least 2 options: ...


1

Since your goal is to predict the price, I think it would be more useful to include features such as: distance between origin and destination whether origin and destination are in the same state/country/continent/area... However the actual origin and destination might still be useful, at least the frequent ones, so it's worth experimenting. Those which ...


1

Probability vectors are meant for discrete random variables. Your data is drawn from a continuous distribution. In order to get a probability vector from data, you need to bin it into a normalized histogram. This gets you a probability vector. You probably want to make sure though, that bin center and width for samples from both distributions are the same. ...


1

Define your own distance function. I suggest you simply use dist(x,y)=haversine(x[0],y[0])+haversine(x[1],y[1])


1

Feature engineering is the name of the game when it comes to this cases. I stumbled upon a similar problem a few years ago and it can be baffling to have a model nor generalize well for all cases. However, one model for one user is never the way to go, after all you, in many cases have only one data point for that user in particular. Additionally, you will ...


1

To get location based tweets, you have to specify a location circle with center (lat and long) and radius using reverse_geocode. There is no way to find tweets by setting a polygon or drawing a border.


1

Overly simple answer: "animate" this in PowerPoint by having one slide per time slice then advancing the slides quickly with the keyboard or set them to auto-advance. If you have a little more flexibility outside PPT, there are free tools (e.g. Microsoft Power BI) where you could do a shaded map and have a time slider to make it more interactive.


1

This sounds like an unsupervised learning problem since you are trying to group observations according to some common association rather than trying to predict a target. My first impression is that you are facing an uphill battle here as your data set doesn't look comprehensive enough. As a starting point, this is what I would try: You could assume that ...


1

I have done some previous work classifying vehicles (heavy or light) based on their driving behaviors. This required calculating speed and accelerations, which you can easily do by using numerical formulas such as the five-point stencil. You already know that points are separated by 0.25 seconds and the distances can be calculated using the haversine formula....


1

As Spacedman put it, "best" is pretty subjective. However, as we have found, a good format for time is Unix time (aka POSIX time, aka Epoch time). Most databases support it and it is still pretty human readable. For location, we like decimal degrees as it is easy to read and stored and is compatible with Google Maps API. It's also easy to convert to other ...


Only top voted, non community-wiki answers of a minimum length are eligible