JAVA 協同過濾演算法商品推薦

2021-07-25 21:52:11 字數 1801 閱讀 9075

public

double getnumbycustomer(customer customer)

}return vectore;

}

public

double

countsimilarity(double a,double b)

return result;

}

public list> getmaxsimilarity(customer customer)

}list> list = new linkedlist>( result.entryset() );

collections.sort( list, new comparator>()

} );

return list;

}

public mapgetproducts(list.entry

> list)

mapmap =new hashmap();

for(customer customer:simcustomers)else

map.put(entry.getkey(),model);}}

return map;

}

public mapgetallsimilarity(customer customer) throws ioexception 

inputstream inputstream = this.getclass().getclassloader().getresourceasstream("cxtx.properties");

properties p = new properties();

try catch (ioexception e1)

string folderpath = p.getproperty("recommendfile");

file file=new file(folderpath);

if(!file.exists())

fileinputstream fileinputstream=new fileinputstream(file);

mapmap =new hashmap();

com.alibaba.fastjson.jsonobject jsonobject = null;

try

} catch (ioexception e)

object content=null;

if(jsonobject==null)

jsonobject object=new jsonobject(temp);

bufferedwriter.write(object.tostring());

bufferedwriter.flush();

if(object!=null)

}else

}map.put("msg","獲取成功");

map.put("content",content);

return map;

}

1.使用者相似度計算時,要考慮分母為0的情況;同時要防止數值太大,超過了double能表示的範圍,可以做一些處理,例如除以最大的某個商品銷售量,來表示某個維度的向量值,或者減去某個值等等

2.余弦值越接近1,表明兩個向量越相似,即計算出來的值越大,使用者行為越相似

3.最後獲得推薦的商品數量可以較多或較少,要根據一定策略進行排序,例如相似使用者的購買數量,而不是商品總的銷售量,因為不相似使用者的資料,容易產生干擾。

協同過濾推薦演算法 協同過濾推薦演算法總結

推薦演算法具有非常多的應用場景和商業價值,因此對推薦演算法值得好好研究。推薦演算法種類很多,但是目前應用最廣泛的應該是協同過濾類別的推薦演算法,本文就對協同過濾類別的推薦演算法做乙個概括總結,後續也會對一些典型的協同過濾推薦演算法做原理總結。推薦演算法概述 1 基於內容的推薦 這一類一般依賴於自然語...

協同過濾推薦演算法 推薦演算法 基於協同過濾CF

前邊我們已經介紹了推薦演算法裡的基於內容的推薦演算法cb,今天我們來介紹一下基於協同的推薦演算法collaboration filtering cf 協同過濾是乙個利用群體智慧型的乙個演算法,舉乙個簡單的例子,如果放假了你想去北京玩幾天,但是不知道北京都有哪些好玩的,你會怎麼做?你可能會上網查一下的...

協同過濾推薦演算法

協同過濾推薦演算法 分為基於使用者的協同過濾推薦usercf和基於物品的協同過濾推薦itemcf。介紹見 協同過濾的實現步驟 1 指導思想 這種過濾演算法的有效性基礎在於 1 使用者偏好具有相似性,即使用者可分類。這種分類的特徵越明顯,推薦準確率越高 2 物品之間具有相似性,即偏好某物品的人,都很可...