how can i handle type data for spatial clustering using DBSCAN with python?

259 views Asked by At

I want to cluster location using gowalla dataset.[this is my data contain user id (int), check-in time(polynomial), latitude(real), longitude(real), location(int)]

And i have an error like this.

what's wrong with my code??

import csv
import numpy as np
from scipy.spatial import distance
from sklearn.cluster import DBSCAN

labels = ['id', 'date_time', 'lat', 'lng','location']
data = csv.DictReader(open('dataset1.csv', 'r').readlines()[1:], labels)
coords = [(float(d['lat']), float(d['lng'])) for d in data if len(d['lat']) > 0]
distance_matrix = distance.squareform(distance.pdist(coords))

db = DBSCAN(eps=1.45).fit(distance_matrix)
class_members = [index[0] for index in np.argwhere(db.labels_ == k)]
for index in class_members:
    print '%s,%s' % (int(k), '{0},{1}'.format(*coords[index]))

thanks for helping n sharing

1

There are 1 answers

0
Has QUIT--Anony-Mousse On

As the error message stated, None does not have a length.

if len(d['lat']) > 0

so d['lat'] must be None.

At least one row doesn't have a coordinate?