필터 지우기
필터 지우기

How to run k means clustering on multiple items in a text file

조회 수: 1 (최근 30일)
Aaron
Aaron 2013년 10월 12일
답변: Yatin 2013년 10월 14일
I am trying to find a way to run k-means clustering on data from the attached text file. The first column shows an individual item. for example: A8888888888888888880011 is one item and it appears several times in the data. I would like to run k means clustering for each item in the text file (the one provided is shortened by a few thousand lines). I read the data in and sort it by using:
fid = fopen(filename);
cell_data = textscan(fid, '%s %n %n');
fclose(fid);
matrix_data = [cell_data{:}];
sort_data = sortrows(matrix_data, [1,3]);
After this I would like to have one coordinate for each item. The coordinate being the result of k means clustering returning a point (column b, column c).
So after running this on the text file, I would end up with 3 points, one for item 11, 12, and 13.
I hope this makes sense but if there are any questions please ask
  댓글 수: 4
sixwwwwww
sixwwwwww 2013년 10월 14일
In your example, you have a cluster of 8 elements(7 x and 1 y). So can we take mean of 8 points as a cluster point? or should we select 1 of these 8 points strictly?
Jonathan LeSage
Jonathan LeSage 2013년 10월 14일
Could you clarify what data you are trying to cluster in your example? Are you trying to cluster column one data or column two as one-dimensional vectors? Or are you trying to cluster two-dimensional data?

댓글을 달려면 로그인하십시오.

채택된 답변

Yatin
Yatin 2013년 10월 14일
Hi,
You can try using the "kmeans" function by formatting your data as per the data format required in the function. The function returns the centroid of the cluster which is the best representation of the cluster. For more information you can refer to the link below:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cluster Analysis and Anomaly Detection에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by