public ISimpleKnnModel TrainModel(List <IUser> trainUsers, List <IArtist> artists, List <IRating> trainRatings) { var model = new SimpleKnnModel(); foreach (var user in trainUsers) { model.Users.Add(SimpleKnnUser.FromIUser(user)); } return(model); }
public float PredictRatingForArtist(IUser user, ISimpleKnnModel model, List <IArtist> artists, int artistIndex, int nearestNeighboursCount) { var knnUser = SimpleKnnUser.FromIUser(user); var neighbours = CalculateKNearestNeighbours(knnUser, model.Users, nearestNeighboursCount); if (neighbours.Count == 0) { return(1.0f); } return(RecommendationGenerator.PredictRatingForArtist(knnUser, neighbours, model, artists, artistIndex)); }
public IEnumerable <IRecommendation> GenerateRecommendations(IUser user, ISimpleKnnModel model, List <IArtist> artists, int nearestNeighboursCount) { var knnUser = SimpleKnnUser.FromIUser(user); var neighbours = CalculateKNearestNeighbours(knnUser, model.Users, nearestNeighboursCount); if (neighbours.Count == 0) { return(null); } return(RecommendationGenerator.GenerateRecommendations(knnUser, neighbours, model, artists)); }