How to make Cosine Distance classification

4 ビュー (過去 30 日間)
Kong
Kong 2020 年 3 月 12 日
編集済み: Abbas Cheddad 2024 年 5 月 22 日
Hello.
I have 90 dataset (10 label x 9 data).
I want to classfy the dataset using Cosine Distance.
How can use the below code to classify ?
function Cs = getCosineSimilarity(x,y)
%
% call:
%
% Cs = getCosineSimilarity(x,y)
%
% Compute Cosine Similarity between vectors x and y.
% x and y have to be of same length. The interpretation of
% cosine similarity is analogous to that of a Pearson Correlation
%
% R.G. Bettinardi
% -----------------------------------------------------------------
if isvector(x)==0 || isvector(y)==0
error('x and y have to be vectors!')
end
if length(x)~=length(y)
error('x and y have to be same length!')
end
xy = dot(x,y);
nx = norm(x);
ny = norm(y);
nxny = nx*ny;
Cs = xy/nxny;
  1 件のコメント
Abbas Cheddad
Abbas Cheddad 2024 年 5 月 22 日
編集済み: Abbas Cheddad 2024 年 5 月 22 日
Cs = xy/nxny;
Should be written as:
Cs = 1 - xy/nx/ny;
This will give you the cosine distance.

サインインしてコメントする。

採用された回答

Raunak Gupta
Raunak Gupta 2020 年 3 月 16 日
Hi,
I think the answer to the above question is provided in a similar question here. You may find it useful.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClassification Ensembles についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by