Predict() public method

public Predict ( int user_id, int item_id ) : double
user_id int
item_id int
return double
	public static void Main(string[] args)
	{
		// load the data
		var training_data = ItemData.Read(args[0]);
		var test_data = ItemData.Read(args[1]);

		// set up the recommender
		var recommender = new MostPopular();
		recommender.Feedback = training_data;
		recommender.Train();

		// measure the accuracy on the test data set
		var results = recommender.Evaluate(test_data, training_data);
		foreach (var key in results.Keys)
			Console.WriteLine("{0}={1}", key, results[key]);
		Console.WriteLine(results);

		// make a score prediction for a certain user and item
		Console.WriteLine(recommender.Predict(1, 1));
	}
示例#2
0
        ///
        public override float Predict(int user_id, int item_id)
        {
            if (user_id > MaxUserID || item_id > MaxItemID)
            {
                return(float.MinValue);
            }

            int result = 1;
            int ac;

            foreach (int a in item_attributes[item_id])
            {
                if (attribute_count_by_user[user_id].TryGetValue(a, out ac))
                {
                    result += ac;
                }
            }
            return((float)result * (most_popular.Predict(user_id, item_id) + 1) / (item_attributes[item_id].Count + 1));
            // +1 guarantees that songs with a user-accessed attribute are ranked above other songs,
            //    even if they have a count of zero.
            // TODO think about other kinds of normalization
        }
示例#3
0
    public static void Main(string[] args)
    {
        // load the data
        var user_mapping = new EntityMapping();
        var item_mapping = new EntityMapping();
        var training_data = ItemRecommendation.Read(args[0], user_mapping, item_mapping);
        var relevant_users = training_data.AllUsers; // users that will be taken into account in the evaluation
        var relevant_items = training_data.AllItems; // items that will be taken into account in the evaluation
        var test_data = ItemRecommendation.Read(args[1], user_mapping, item_mapping);

        // set up the recommender
        var recommender = new MostPopular();
        recommender.Feedback = training_data;
        recommender.Train();

        // measure the accuracy on the test data set
        var results = ItemPredictionEval.Evaluate(recommender, test_data, training_data, relevant_users, relevant_items);
        foreach (var key in results.Keys)
            Console.WriteLine("{0}={1}", key, results[key]);

        // make a prediction for a certain user and item
        Console.WriteLine(recommender.Predict(user_mapping.ToInternalID(1), item_mapping.ToInternalID(1)));
    }