public Form_SlopeOne() { InitializeComponent(); // 默认选择第一个数据集 this.comboBox1.SelectedIndex = 0; // 读取数据,得到训练用户集合以及测试用户集合 obj_ReadData = new cReadinData(this.comboBox1.SelectedIndex); obj_AssStrategy = new cAssStrategy(); testUsers = cReadinData.getTestUser(); trainUsers = cReadinData.getBaseUser(); this.dataGridView1.RowHeadersVisible = false; this.dataGridView2.RowHeadersVisible = false; for (int i = 0; i < count_Num.Length; i++) { count_Num[i] = 0; stat_Info[i] = 0; } // 根据选择的数据集,填充用户ID的下拉列表 for (int i = 0; i < testUsers.Length - 1; i++) { this.comboBox2.Items.Add(testUsers[i + 1].id); } // 用户ID默认选择第一个 this.comboBox2.SelectedIndex = 0; obj_SlopeOne = new SlopeOne(); for (int i = 1; i < trainUsers.Length; i++) { userRating = new Dictionary <int, float>(); //count_Num[trainUsers[i].RatingNums/20]++; for (int j = 1; j < trainUsers[i].Ratings.Length; j++) { if (trainUsers[i].Ratings[j] != 0) { userRating.Add(j, (float)trainUsers[i].Ratings[j]); } } obj_SlopeOne.AddUserRatings(userRating); } this.comboBox3.Items.Clear(); // 填充 连续运行用户数目 下拉列表 for (int i = 15; i < testUsers.Length; i++) { comboBox3.Items.Add(i); } this.comboBox3.SelectedIndex = 0; }
public Form_SlopeOne() { InitializeComponent(); // 默认选择第一个数据集 this.comboBox1.SelectedIndex = 0; // 读取数据,得到训练用户集合以及测试用户集合 obj_ReadData = new cReadinData(this.comboBox1.SelectedIndex); obj_AssStrategy = new cAssStrategy(); testUsers = cReadinData.getTestUser(); trainUsers = cReadinData.getBaseUser(); this.dataGridView1.RowHeadersVisible = false; this.dataGridView2.RowHeadersVisible = false; for (int i = 0; i < count_Num.Length; i++) { count_Num[i] = 0; stat_Info[i] = 0; } // 根据选择的数据集,填充用户ID的下拉列表 for (int i = 0; i < testUsers.Length - 1; i++) { this.comboBox2.Items.Add(testUsers[i + 1].id); } // 用户ID默认选择第一个 this.comboBox2.SelectedIndex = 0; obj_SlopeOne = new SlopeOne(); for (int i = 1; i < trainUsers.Length; i++) { userRating = new Dictionary<int, float>(); //count_Num[trainUsers[i].RatingNums/20]++; for (int j = 1; j < trainUsers[i].Ratings.Length; j++) { if (trainUsers[i].Ratings[j] != 0) { userRating.Add(j, (float)trainUsers[i].Ratings[j]); } } obj_SlopeOne.AddUserRatings(userRating); } this.comboBox3.Items.Clear(); // 填充 连续运行用户数目 下拉列表 for (int i = 15; i < testUsers.Length; i++) { comboBox3.Items.Add(i); } this.comboBox3.SelectedIndex = 0; }
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)); }
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)); }
public void Check_Slope_One_Method() { MyEntityContext ctx = Application.Context; List <IAgent> agents = new List <IAgent>(); IAgent a = null; agents.Add(a = ctx.Agents.Create()); a.Name = "John"; a.Role = RoleEnum.Buyer; agents.Add(a = ctx.Agents.Create()); a.Name = "Mark"; a.Role = RoleEnum.Buyer; agents.Add(a = ctx.Agents.Create()); a.Name = "Lucy"; a.Role = RoleEnum.Buyer; List <IObject> objs = new List <IObject>(); IObject o = null; objs.Add(o = ctx.Objects.Create()); o.Name = "Subj 1"; objs.Add(o = ctx.Objects.Create()); o.Name = "Subj 2"; objs.Add(o = ctx.Objects.Create()); o.Name = "Subj 3"; List <ILikes> likes = new List <ILikes>(); ILikes l = null; likes.Add(l = ctx.Likess.Create()); l.Agent = agents[0]; l.Object = objs[0]; l.Value = 5; likes.Add(l = ctx.Likess.Create()); l.Agent = agents[0]; l.Object = objs[1]; l.Value = 3; likes.Add(l = ctx.Likess.Create()); l.Agent = agents[0]; l.Object = objs[2]; l.Value = 2; likes.Add(l = ctx.Likess.Create()); l.Agent = agents[1]; l.Object = objs[0]; l.Value = 3; likes.Add(l = ctx.Likess.Create()); l.Agent = agents[1]; l.Object = objs[1]; l.Value = 4; likes.Add(l = ctx.Likess.Create()); l.Agent = agents[2]; l.Object = objs[1]; l.Value = 2; likes.Add(l = ctx.Likess.Create()); l.Agent = agents[2]; l.Object = objs[2]; l.Value = 5; SlopeOne so = new SlopeOne(); so.Likes = likes; so.DEBUG = true; so.Process(); Console.WriteLine("------------ Estimations -------------"); Console.WriteLine("Estimation for John and Subj 3 is " + so.Estimate(agents[1], objs[2])); Console.WriteLine("Estimation for Marc and Subj 3 is " + so.Estimate(agents[1], objs[2])); Console.WriteLine("Estimation for Lucy and Subj 1 is " + so.Estimate(agents[2], objs[0])); Assert.True(true); }
static void Main(string[] args) { SlopeOne slope = new SlopeOne(); slope.ReadData(@"C:\Users\Admin\Desktop\Assignment7.csv"); //slope.Run(); var rate = slope.PredictFor(1, 1); //NBC nbc = new NBC(); //nbc.Verdict(); Console.WriteLine("Rate: {0}", rate); //Console.WriteLine //var x = nbc.Probability(true); //var y = nbc.Probability(false); Console.ReadKey(); //var reddit = new Reddit(@"C:\Users\col403\Desktop\reddit.csv"); //reddit.ReadData(); //reddit.RankNews(); //reddit.Print(); //Task3 task = new Task3(@"C:\Users\col403\Desktop\ml-latest-small\movies.csv", // @"C:\Users\col403\Desktop\ml-latest-small\ratings.csv"); //var dm = task.DampedMeanCollection(); //var dampedTop10 = dm.OrderByDescending(x => x.Value).Take(10); //foreach(var d in dampedTop10) //{ // string similar = task.GetMovieName(task.GetMostSimilar(d.Key)); // Console.WriteLine("{0} damped mean: {1}. Similar to {2}",task.GetMovieName(d.Key), d.Value, similar); //} //var fdsx = task.SimilarityValue(4324, 4234); //string similar = task.GetMovieName(task.GetMostSimilar(8)); //Console.ReadKey(); }