我有以下数据框:关于数据和框架的历史很少。这是第二个版本,初始数据框具有基于列标题表示的实际相似性值。根据实际的相似性值,每个都由它们所属的 bin 标识,我认为 bin 是实际分数。
cosinFcolor cosinEdge cosinTexture histoFcolor histoEdge histoTexture jaccard
1 3 0 0 1 1 0 0
2 0 0 5 0 2 2 0
3 1 0 2 0 0 1 0
4 0 0 3 0 1 1 0
5 1 3 1 0 4 0 0
6 0 0 1 0 0 0 0
我想要做的是对每一行值求和并将其保存在 jaccard 列旁边的列中,但在求和过程中我想检查 jaccard 的值,这是我想要根据 jaccard 值执行的 sudo 代码:
这是须藤代码:
If jaccard.value of that row == 5
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .5)
If jaccard.value of that row == 4
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .4)
If jaccard.value of that row == 3
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture)+= (jaccard.value of the row * .3)
If jaccard.value of that row == 2
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .2)
If jaccard.value of that row == 1
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .1)
else if jaccard.value of that row == 0
value in the new column is = -1
完成此操作后,我希望最终数据帧如下所示:
cosinFcolor cosinEdge cosinTexture histoFcolor histoEdge histoTexture jaccard weightedScore
1 3 0 0 1 1 0 0 -1
2 0 0 5 0 2 2 0 -1
3 1 0 2 0 0 1 0 -1
4 0 0 3 0 1 1 0 -1
5 1 3 1 0 4 0 0 -1
6 0 0 1 0 0 0 0 -1
7 0 0 1 0 0 0 1 1.1
我的初始(我放置的第一个数据框)是在 StackOverflow 用户的帮助下通过遵循 R 代码生成的:
这是R代码:
single_img_sim_no_title <- single_img_similarity
single_img_sim_no_title$title <- NULL
head(single_img_sim_no_title)
#converting it to bins
sing_img_bins <- apply(single_img_sim_no_title, 2, cut, c(-Inf, seq(0.5, 1, 0.1), Inf), labels=0:6)
sing_img_bins[sing_img_bins=="6"] <- "0"
sing_img_bins <- as.data.frame(sing_img_bins)