-1
나는 여기에서 새롭다. 그리고 나는이 문제에 대해 유감스럽게 생각한다. 너희 중 몇 사람에게는 너무 어리 석다. 대학에서 k-mean 클러스터링에 C++ 프로젝트를해야하는데 도움이 필요합니다. 다음은 코드입니다. 그것은 효과가있다. 이제 G-Matrix를 별도로 만들어야합니다. 코드 내에서 내가 다음 얻을 : 중심의C++ : K- 평균 클러스터링 G- 매트릭스
4.30 0.50 * 1 *
3.54 0.50 * 1 *
0.71 3.20 * 0 *
0.71 4.61 * 0 *
좌표은 다음과 같습니다
4.50
3.50
중심의 좌표는 다음과 같습니다
1.50
1.00
이 괜찮지 만, 내가 필요 다음과 같은 추가 G- 매트릭스의 1,1,0,0
:
A B C D
1 1 0 0 ->c1
0 0 1 1 ->c2
여기에서 A,B,C,D
은 포인트이고 c1
및 c2
은 중심입니다. 이것을 표시하는 방법을 알려주세요. 여기
내 코드 : 당신의 도움에 대한
float dmin, dpoint;
float sum[2][2];
int cluster[4], count[4], group;
float flips;
const int rows = 4;
const int columns = 2;
const int crows = 2;
const int ccolumns = 2;
// initialize the points
int point[rows][columns]={{1,1},{2,1},{4,3},{5,4}};
// initialize the centroids
double centroid [crows][ccolumns] = {{1,1},{2,1}};
// ...
for (i = 0; i<4; i++) cluster[i] = 0;
// until there is no change of clusters belonging to each pattern, continue
flips = 4;
while (flips>0) {
flips = 0;
for (j = 0; j < 2; j++)
{
count[j] = 0;
for (i = 0; i < 2; i++)
sum[j][i] = 0;
}
// now, we need to calculate the distance
for (i = 0; i < 4; i++) {
dmin = 2; group = cluster[i];
for (j = 0; j < 2; j++)
{
dpoint = 0.0;
dpoint += sqrt(pow((point[i][0] - centroid[j][0]),2)+pow((point[i][1] - centroid[j][1]),2));
fprintf(stdout, "%5.2f ", dpoint); // Show the value of the distance
if (dpoint < dmin) {
group = j;
dmin = dpoint;
}
}
// now, we need to calculate the G matrix (1 or 0)
fprintf(stdout, " * %d *\n", group); // displays 0 or 1 (to which cluster it belongs)
if (cluster[i] != group)
{
flips++;
cluster[i] = group; // repeat this process until G(n)=G(n+1)
}
count[cluster[i]]++;
for (j = 0; j < 2; j++)
sum[cluster[i]][j] += point[i][j];
}
// now, display the coordinates of the centroid
for (i = 0; i < 2; i++) {
fprintf(stderr," The coordinates of the centroid are: \n");
for (j = 0; j < 2; j++) {
centroid[i][j] = sum[i][j]/count[i];
fprintf(stderr, "%5.2f \n", centroid[i][j]);
}
}
}
}
감사합니다!
이 문맥에서 K는 무엇입니까? 얼마나 많은 클러스터를 파티셔닝할까요? – taocp
숙제 연습? – Roalt
G 매트릭스 란 무엇입니까? –