使用 RMSE 计算相似度

问题描述 投票:0回答:1

我有以下数据:

物体 l2a l2b l4 l5
a 0.6649 0.5916 0.033569 0.557373
b 0.8421 0.5132 0.000000 0.697193
c 0.6140 0.2807 0.084217 0.650313
d 0.7619 0.3810 0.000000 0.662306
e 0.6957 0.3043 0.000000 0.645135

是否可以使用 RMSE 来测量 (a-b)、(a-c)、(a-d)、(a-e)、(b-c)、...、(d,e) 之间的相似度?

例如:

对象a(_a)和对象b(_b)之间的相似性:

diff_l2a = l2a_a - l2a_b

diff_l2b = l2b_a - l2b_b

diff_l4 = l4_a - l4_b

diff_l5 = l5_a - l5_b

然后计算RMSE:

RMSEs = [RMSE(diff_l2a, diff_l2b), RMSE(diff_l2a, diff_l4), RMSE(diff_l2a, diff_l5), ..., RMSE(diff_l4, diff_l5)]

相似之处:

average(RMSEs)
python machine-learning scikit-learn similarity mse
1个回答
0
投票

RMSE 相似度 DF 代码:

import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error

num_objects = len(df)
similarity_matrix = np.zeros((num_objects, num_objects))

for i in range(num_objects):
    for j in range(i + 1, num_objects):
        rmse = np.sqrt(mean_squared_error(attributes[i], attributes[j]))
        similarity_matrix[i, j] = rmse
        similarity_matrix[j, i] = rmse

similarity_df = pd.DataFrame(similarity_matrix, columns=df['object'], index=df['object'])

我现在正在实现测试代码..

© www.soinside.com 2019 - 2024. All rights reserved.