I recently learned about e-commerce websites. Many websites are using custom lines. In the information system, personalized customization is system recommendation, and information that matches user preferences or user operations
There are many ways to achieve this recommendation by presenting it in the form of subscription or webpageAlgorithmAnd the processing method, but I think a more reliable approach is to implicitly rate the product or information, and then recommend this method.
This method does not require too much user participation. Instead, you do not need to manually score a product. Instead, you need to perform user operations, such as viewing, purchasing, and commenting.
This method is slope one #CodePost it for your reference.
Here's the source code of my C # Implementation of weighted slope one. Tested on. NET 3.5; the instruction in Chinese can be found here and here.
Reference:
Tutorial about how to implement slope one in Python
Slope one predictors for online rating-based collaborative filtering
Recommender systems: slope one
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace slopeone
{
Public class rating
{
Public float value {Get; set ;}
Public int freq {Get; set ;}
Public float averagevalue
{
Get {return value/freq ;}
}
}
Public class ratingdifferencecollection: dictionary <string, rating>
{
Private string getkey (INT item1id, int item2id)
{
Return (item1id <item2id )? Item1id + "/" + item2id: item2id + "/" + item1id;
}
Public bool contains (INT item1id, int item2id)
{
Return this. Keys. Contains <string> (getkey (item1id, item2id ));
}
public rating this [int item1id, int item2id]
{< br> get {
return this [this. getkey (item1id, item2id)];
}< br> set {This [this. getkey (item1id, item2id)] = value ;}< BR >}
public class slopeone
{< br> Public ratingdifferencecollection _ diffmarix = new ratingdifferencecollection (); // The dictionary to keep the diff matrix
Public hashset _ items = new hashset (); // tracking how many items totally
Public void adduserratings (idictionary userratings)
{< br> foreach (VAR Item1 in userratings)
{< br> int item1id = item1.key;
float item1rating = item1.value;
_ items. add (item1.key);
Foreach (VAR item2 in userratings)
{
If (item2.key <= item1id) continue; // eliminate redundancy
Int item2id = item2.key;
Float item2rating = item2.value;
Rating ratingdiff;
If (_ diffmarix. Contains (item1id, item2id ))
{
Ratingdiff = _ diffmarix [item1id, item2id];
}
Else
{
Ratingdiff = new rating ();
_ Diffmarix [item1id, item2id] = ratingdiff;
}
ratingdiff. Value + = item1rating-item2rating;
ratingdiff. freq + = 1;
}< BR >}
// input ratings of all users
Public void adduerratings (ilist ratings)
{< br> foreach (VAR userratings in ratings)
{< br> adduserratings (userratings);
}< BR >}
Public idictionary <int, float> predict (idictionary <int, float> userratings)
{
Dictionary <int, float> predictions = new dictionary <int, float> ();
Foreach (VAR Itemid in this. _ items)
{
If (userratings. Keys. Contains (Itemid) continue; // user has rated this item, just skip it
Rating itemrating = new rating ();
Foreach (VAR userrating in userratings)
{
If (userrating. Key = Itemid) continue;
Int inputitemid = userrating. Key;
If (_ diffmarix. Contains (Itemid, inputitemid ))
{
Rating diff = _ diffmarix [Itemid, inputitemid];
Itemrating. Value + = diff. freq * (userrating. Value + diff. averagevalue * (Itemid <inputitemid )? 1:-1 ));
Itemrating. freq + = diff. freq;
}
}
Predictions. Add (Itemid, itemrating. averagevalue );
}
Return predictions;
}
Public static void test ()
{
Slopeone test = new slopeone ();
dictionary userrating = new dictionary ();
userrating. add (1, 5);
userrating. add (2, 4);
userrating. add (3, 4);
test. adduserratings (userrating);
userrating = new dictionary ();
userrating. add (1, 4);
userrating. add (2, 5);
userrating. add (3, 3);
userrating. add (4, 5);
test. adduserratings (userrating);
Userrating = new dictionary <int, float> ();
Userrating. Add (1, 4 );
Userrating. Add (2, 4 );
Userrating. Add (4, 5 );
Test. adduserratings (userrating );
Userrating = new dictionary <int, float> ();
Userrating. Add (1, 5 );
Userrating. Add (3, 4 );
idictionary predictions = test. predict (userrating);
foreach (VAR rating in predictions)
{< br> console. writeline ("item" + rating. key + "rating:" + rating. value);
}< BR >}< br>