How do we Calculate Distance Matrix for Data Set in an Excel file
5 ビュー (過去 30 日間)
古いコメントを表示
Dear experiences...
i have a dataset D which includes N points in M dimensional space, data set stored in an excel file called (data.xls)
in this excel file ... (data view)
- first column (A) is my data points name (x1,x2,...xn),
- columns from (B ... M) are features where features are weighted according to some calculation.. where n in may data set = 127 and m=1200.
- Xij includes features weights for (i=1..n), (j=1..m)
*i need to calculate distance matrix based on (cosine distance)..where procedure i think its look like the following:
1- every row of Xi (data-point) is normalized to be (unite length=1) independent from others .. where the result matrix is includes normalized data points.
2- after that distance matrix applied based on cosine distance where cosine distance (i think) = 1-cosine similarity (dot product) .
i would thank any one can give me a help to import dataset in matlab and perform my requirements.. due i'm new to matlab?
0 件のコメント
採用された回答
Guillaume
2017 年 3 月 13 日
編集済み: Guillaume
2017 年 3 月 13 日
1. Normalising the rows is easy:
NormalisedMatrix = OriginalMatrix ./ sqrt(sum(NormalisedMatrix .^ 2, 2));
2. Getting the cosine similarity is also fairly simple. I#m using the formula in this wikipedia article:
cossimilarity = @(a, b) sum(a.*b, 2) ./ sqrt(sum(a.^2, 2) .* sum(b.^2, 2));
similarity = squeeze(cossimilarity(OriginalMatrix, permute(OriginalMatrix, [3 2 1]))); %assumes R2016b
cosdistance = 1 - similarity;
The above gives you a NxN symmetric matrix of the similarity and distance between each vector.
8 件のコメント
Guillaume
2017 年 3 月 14 日
"can you please update this code to be work under 2015a"
I wrote, just above, "In previous versions:", followed by the two lines that need to be replaced to work in all versions before R2016b, including R2015a.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!