How do we Calculate Distance Matrix for Data Set in an Excel file
4 次查看(过去 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!