2014-03-02 2 views
0

두 개의 열 (타임 스탬프위도/경도)이있는 큰 데이터 세트가 있습니다. 나는 좌표를 서로 묶어서 기록되는 서로 다른 장소의 수를 결정하고 서로의 일정한 거리 내의 모든 것을 모든 하나의 위치로 간주하기를 원합니다. 본질적으로이 데이터 세트에 얼마나 많은 "장소"가 있는지 파악하고 싶습니다. A good visual example is this 나는 여기에 집중하고 싶지만 클러스터가 내 데이터 세트와 어디에 있는지 알지 못한다.지리 좌표 데이터 집합 비닝/그룹화

+2

; 예를 들어 [here] (http://scikit-learn.org/stable/modules/clustering.html#clustering) –

답변

1

는 behzad.nouri의 참조에 더 자세히

# X= your Geo Array 

# Standardize features by removing the mean and scaling to unit variance 
X = StandardScaler().fit_transform(X) 

# Compute DBSCAN 
db = DBSCAN(eps=0.3, min_samples=3).fit(X) 

# HERE 
# eps -- The maximum distance between two samples 
# for them to be considered as in the same neighborhood. 
# min_samples -- The number of samples in a neighborhood for a point 
# to be considered as a core point. 

core_samples = db.core_sample_indices_ 
labels = db.labels_ 

# Number of clusters in labels, ignoring noise if present. 
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0) 
+0

추가 정보를 보내 주셔서 감사합니다. "오 .. 수학이 많아서" "OK, 나도 할 수있어." –

0

이 사이비 코드는 격자 파티션에 포인트의 수를 집계하는 동안 그리드 파티션 당 하나의 점으로 점 세트를 감소하는 방법을 보여줍니다. 이는 일부 영역이 희소하고 다른 영역이 밀도가 높지만 표시된 점 (예 :지도)의 균일 한 분포가 필요한 점 집합이있는 경우 유용 할 수 있습니다.

이 기능을 사용하기 위해 축 세트 (예 : X) 중 하나에 포인트 세트와 파티션 수가 전달됩니다. 다른 축 (예 : Y)에서 동일한 분할이 사용됩니다. 따라서 3을 지정하면 같은 크기의 파티션이 9 (3 * 3) 개 만들어집니다. 이 함수는 먼저 점 집합을 통해 전체 세트를 묶는 가장 바깥 쪽 X 및 Y (최소 및 최대) 좌표를 찾습니다. 가장 바깥 쪽 X와 Y 축 사이의 거리를 그리드 크기를 결정하기 위해 분할 수로 나눈다.

이 함수는 각 그리드 파티션을 단계별로 실행하고 세트의 각 포인트가 그리드 파티션 내에 있는지 확인합니다. 포인트가 그리드 파티션 내에 있으면, 이것이 그리드 파티션에서 첫 번째 포인트인지 확인합니다. 예인 경우, 첫 번째 점이 발견되었음을 나타 내기위한 플래그가 설정됩니다. 그렇지 않으면 그리드 파티션의 첫 번째 점이 아닌 점이 점 집합에서 제거됩니다.

파티션에있는 각 지점에 대해 함수는 집계 계수를 증가시킵니다. 마지막으로, 감소/집계가 그리드 파티션 당 완료되면, 하나는 다음 집계 지점을 시각화 할 수 있습니다 (예를 들어, 탈리 표시와 함께 단일 지점에서지도에 표시 마커) : 당신은 클러스터링 알고리즘을 필요로

function TallyPoints(array points, int npartitions) 
{ 
    array partition = new Array(); 

    int max_x = 0, max_y = 0; 
    int min_x = MAX_INT, min_y = MAX_INT 

    // Find the bounding box of the points 
    foreach point in points 
    { 
     if (point.X > max_x) 
      max_x = point.X; 
     if (point.Y < min_x) 
      min_x = point.X; 
     if (point.Y > max_y) 
      max_y = point.Y; 
     if (point.Y < min_y) 
      min_y = point.Y; 
    } 

    // Get the X and Y axis lengths of the paritions 
    float partition_length_x = ((float) (max_x - min_x))/npartitions; 
    float partition_length_y = ((float) (max_y - min_y))/npartitions; 

    // Reduce the points to one point in each grid partition 
    // grid partition 
    for (int n = 0; n < npartitions; n++) 
    { 
     // Get the boundary of this grid paritition 
     int min_X = min_x + (n * partition_length_x); 
     int min_Y = min_y + (n * partition_length_y); 
     int max_X = min_x + ((n + 1) * partition_length_x); 
     int max_Y = min_y + ((n + 1) * partition_length_y); 

     // reduce and tally points 
     int  tally = 0; 
     boolean reduce = false; // set to true after finding the first point in the paritition 
     foreach point in points 
     { 
      // the point is in the grid parition 
      if (point.X >= min_x && point.X < max_x && 
       point.Y >= min_y && point.X < max_y) 
      { 
       // first point found 
       if (false == reduce) 
       { 
        reduce = true; 
        partition[ n ].point = point; // keep this as the single point for the grid 
       } 
       else 
        points.Remove(point); // remove the point from the list 

       // increment the tally count 
       tally++; 
      } 
     } 

     // store the tally for the grid 
     partition[ n ].tally = tally; 

     // visualize the tallied point here (e.g., marker on Google Map) 
    } 
} 
관련 문제