Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // 记录当前时间
            int      count_predit = 0;
            DateTime dt_1         = DateTime.Now;

            Rec_Items_num = int.Parse(this.textBox9.Text);
            userRating    = new Dictionary <int, float>();

            // 得到用户
            cUser testUser = testUsers[comboBox2.SelectedIndex + 1];

            userid = testUser.id;

            userRating = new Dictionary <int, float>();

            for (int j = 1; j < trainUsers[userid].Ratings.Length; j++)
            {
                if (trainUsers[userid].Ratings[j] != 0)
                {
                    userRating.Add(j, (float)trainUsers[userid].Ratings[j]);
                }
            }
            //    count_predit = trainUsers[userID].Ratings.Length - trainUsers[userID].RatingNums;

            // 得到该用户的预测评分
            IDictionary <int, float> Predictions = obj_SlopeOne.Predict(userRating);

            obj_AssStrategy = obj_SlopeOne.getAssStrategy(userid, Predictions, Rec_Items_num, testUser);

            DateTime dt_2 = DateTime.Now;
            TimeSpan ts   = dt_2.Subtract(dt_1);

            this.textBox4.Text = obj_AssStrategy.MAE.ToString();        // MAE
            this.textBox5.Text = ts.TotalMilliseconds + "ms";           // 时间
            this.textBox6.Text = obj_AssStrategy.Precison.ToString();   // 查准率
            this.textBox8.Text = obj_AssStrategy.Recall.ToString();     // 查全率
            float F = obj_AssStrategy.calculateF_Measure();             // F1指标

            this.textBox7.Text = F.ToString();
            this.textBox2.Text = this.Rec_Items_num.ToString();         // Top-N 推荐数

            this.textBox3.Text = "MAE:" + obj_AssStrategy.MAE + " 查准率:" + obj_AssStrategy.Precison + " 查全率:" +
                                 obj_AssStrategy.Recall + " F值:" + F + " 总耗时:" + ts.TotalMilliseconds + "ms";
            //     this.dataGridView1.Rows.Add(count_dgv++, trainUsers[userIndex].id, this.Rec_Items_num, trainUsers[userIndex].RatingNums, obj_AssStrategy.MAE, obj_AssStrategy.Precison,
            //       obj_AssStrategy.Recall, F, ts.TotalMilliseconds + " ms");
            Application.DoEvents();

            stat_Info[trainUsers[userid].RatingNums / 50] += obj_AssStrategy.MAE;
            count_Num[trainUsers[userid].RatingNums / 50]++;
            // 累加相关数据
            total_MAE       += obj_AssStrategy.MAE;
            total_Precison  += obj_AssStrategy.Precison;
            total_Recall    += obj_AssStrategy.Recall;
            total_F_Measure += F;
            total_Time      += ts.TotalMilliseconds;
        }
        public void TestNewUserInTestSet()
        {
            var recommender = new SlopeOne();

            var training_data = new Ratings();

            training_data.Add(0, 0, 1.0f);
            training_data.Add(1, 1, 5.0f);
            training_data.InitScale();

            recommender.Ratings = training_data;
            recommender.Train();

            Assert.AreEqual(3.0, recommender.Predict(2, 1));
        }
Пример #3
0
        public void TestNewItemInTestSet()
        {
            var recommender = new SlopeOne();

            recommender.MinRating = 1;
            recommender.MaxRating = 5;

            var training_data = new Ratings();

            training_data.Add(0, 0, 1.0);
            training_data.Add(1, 1, 5.0);

            recommender.Ratings = training_data;
            recommender.Train();

            Assert.AreEqual(3.0, recommender.Predict(0, 2));
        }