【发布时间】:2012-05-24 11:23:42
【问题描述】:
我需要做的是,计算两个客户评分之间的点积距离。客户的评分记录在哈希图中。
private HashMap<String,int[]> ratingmap;
hashmap 中的键是客户名称,与之相关的是该客户的评分(他对书籍的评分)
我该怎么做?
/**
* calculate dot product distance between the ratings of two customers
* @param name1 String name of customer
* @param name2 String name of customer
* @return int distance or ILLEGAL_INPUT if name1 or name2 are not customers
*/
public int distance(String name1, String name2)
{
return 0; //replace with code
}
这是RatingsAnalysis 课程中给出的另一点细节
//collection of rated book titles
private BookList books;
//collection of customers and their ratings
private RatingsMap ratings;
//use a list of customer names from the ratings map for looping through the map
private ArrayList<String> customernames;
【问题讨论】:
-
请在此上下文中定义“点积距离”。
-
点积距离是两个客户的评级之间的“密切”关系。就像每个客户都可以对一本书进行评分一样,据我所知,它询问评分的接近程度,即差异
-
但不清楚在这种情况下会涉及什么计算。请编辑您的问题,以举例说明您要执行的计算。
-
难道不只是减去每个客户的所有 int(在这种情况下只有 cust1 和 cust2)
-
在我看来,您想构建两个向量(每个用户一个),其中每个维度都是同一本书的评分?然后计算这些向量的点积。 . .如果没有给出评级,你会填写“0”还是从向量中删除这个维度,bc。 “0”可能与非常负面的评级相同?这对你有意义吗?
标签: java arraylist hashmap dot-product