Train() public method

public Train ( ) : void
return void
Beispiel #1
0
        ///
        public override void Train()
        {
            most_popular.Feedback = Feedback;
            most_popular.Train();

            attribute_count_by_user = new IDictionary <int, int> [MaxUserID + 1];
            for (int u = 0; u < attribute_count_by_user.Count; u++)
            {
                attribute_count_by_user[u] = new Dictionary <int, int>();
            }

            for (int index = 0; index < Feedback.Count; index++)
            {
                int user_id = Feedback.Users[index];
                int item_id = Feedback.Items[index];
                foreach (int a in item_attributes[item_id])                 // TODO speed up
                {
                    if (attribute_count_by_user[user_id].ContainsKey(a))
                    {
                        attribute_count_by_user[user_id][a]++;
                    }
                    else
                    {
                        attribute_count_by_user[user_id][a] = 1;
                    }
                }
            }
        }
Beispiel #2
0
    private static void startMostPopular(ITimedRatings all_data)
    {
        removeUserThreshold(ref all_data);

        Console.WriteLine("Start iteration Test Most Popular ");
        //for (int i = 0; i < 5; i++) {
        ITimedRatings validation_data = new TimedRatings();    // 10%
        ITimedRatings test_data       = new TimedRatings();    // 20%
        ITimedRatings training_data   = new TimedRatings();    // 70%

        readAndSplitData(all_data, ref test_data, ref training_data, ref validation_data);
        IPosOnlyFeedback training_data_pos = new PosOnlyFeedback <SparseBooleanMatrix> ();        // 80%

        for (int index = 0; index < training_data.Users.Count; index++)
        {
            training_data_pos.Add(training_data.Users [index], training_data.Items [index]);
        }


        MyMediaLite.ItemRecommendation.MostPopular recommender = new MyMediaLite.ItemRecommendation.MostPopular();
        recommender.Feedback = training_data_pos;
        DateTime start_time = DateTime.Now;

        recommender.Train();

        Console.Write("Total Training time needed:");
        Console.WriteLine(((TimeSpan)(DateTime.Now - start_time)).TotalMilliseconds);
        Console.WriteLine("Final results in this iteration:");
        var results = MyMediaLite.Eval.ItemsWeatherItemRecommender.EvaluateTime(recommender, validation_data, training_data, "VALIDATION ", false);

        results = MyMediaLite.Eval.ItemsWeatherItemRecommender.EvaluateTime(recommender, test_data, training_data, "TEST ", false);
        //}
    }
	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));
	}
Beispiel #4
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)));
    }