public void ScorePropertyOk() { MovieRatingPrediction aMovieRatingPrediction = new MovieRatingPrediction(); float score = 4.5f; aMovieRatingPrediction.Score = score; Assert.AreEqual(aMovieRatingPrediction.Score, score); }
public void LabelPropertyOk() { MovieRatingPrediction aMovieRatingPrediction = new MovieRatingPrediction(); float label = 1; aMovieRatingPrediction.Label = label; Assert.AreEqual(aMovieRatingPrediction.Label, label); }
public float PredictScore(int userId, int movieId) { MovieRating movieRating = new MovieRating { userId = userId, movieId = movieId }; MovieRatingPrediction prediction = _predictionEnginePool.Predict(modelName: "MovieRatingAnalysisModel", example: movieRating); return(prediction.Score); }
public static void DisplayPrediction(MovieRating example, MovieRatingPrediction prediction) { if (prediction == null) { Console.WriteLine("Task 5 \"Predict\" not completed.\n"); } else { Console.WriteLine("The predicted score of user " + example.userId + " for the movie " + example.movieId + " is: " + Math.Round(prediction.Score, 1) + "\n"); } }
public ActionResult Recommend(int id) { var activeprofile = _profileService.GetProfileByID(id); // 1. Create the ML.NET environment and load the already trained model MLContext mlContext = new MLContext(); ITransformer trainedModel; using (FileStream stream = new FileStream(_movieService.GetModelPath(), FileMode.Open, FileAccess.Read, FileShare.Read)) { trainedModel = mlContext.Model.Load(stream); } //2. Create a prediction function var predictionEngine = trainedModel.CreatePredictionEngine <MovieRating, MovieRatingPrediction>(mlContext); List <(int movieId, float normalizedScore)> ratings = new List <(int movieId, float normalizedScore)>(); var MovieRatings = _profileService.GetProfileWatchedMovies(id); List <Movie> WatchedMovies = new List <Movie>(); foreach ((int movieId, int movieRating) in MovieRatings) { WatchedMovies.Add(_movieService.Get(movieId)); } MovieRatingPrediction prediction = null; foreach (var movie in _movieService.GetTrendingMovies) { // Call the Rating Prediction for each movie prediction prediction = predictionEngine.Predict(new MovieRating { userId = id.ToString(), movieId = movie.MovieID.ToString() }); // Normalize the prediction scores for the "ratings" b/w 0 - 100 float normalizedscore = Sigmoid(prediction.Score); // Add the score for recommendation of each movie in the trending movie list ratings.Add((movie.MovieID, normalizedscore)); } //3. Provide rating predictions to the view to be displayed ViewData["watchedmovies"] = WatchedMovies; ViewData["ratings"] = ratings; ViewData["trendingmovies"] = _movieService.GetTrendingMovies; return(View(activeprofile)); }
public async Task <ActionResult <IEnumerable <MovieVM> > > RecommendMovies(int userId) { var reviews = await _context.Reviews.ToListAsync(); // Lấy id của những phim mà user đã đánh giá var ratedIds = reviews.Where(r => r.AccountId == userId).Select(r => r.MovieId).ToList(); if (ratedIds.Count == 0) { return(NoContent()); } // Sử dụng model để dự đoán rating của userId lên một số phim var recommendedMovies = new List <Movie>(); MovieRatingPrediction prediction = null; foreach (var movie in _context.Movies.OrderBy(x => Guid.NewGuid()).ToList()) { movie.Reviews = null; if (ratedIds.Contains(movie.Id)) { continue; } prediction = _model.Predict(new MovieRating { userId = userId, movieId = movie.Id }); if (prediction.Score >= 7) { recommendedMovies.Add(movie); } // Chỉ recommend 6 phim if (recommendedMovies.Count == 6) { break; } } return(recommendedMovies.Select(m => new MovieVM() { Movie = m, Ratings = AvgRatingsAsync(reviews.Where(r => r.MovieId == m.Id).ToList()) }).ToList()); }
public ActionResult Recommend(int id) { var activeprofile = _profileService.GetProfileByID(id); // 1. Create the ML.NET environment and load the already trained model MLContext mlContext = new MLContext(); List <(int movieId, float normalizedScore)> ratings = new List <(int movieId, float normalizedScore)>(); var MovieRatings = _profileService.GetProfileWatchedMovies(id); List <Movie> WatchedMovies = new List <Movie>(); foreach ((int movieId, int movieRating) in MovieRatings) { WatchedMovies.Add(_movieService.Get(movieId)); } MovieRatingPrediction prediction = null; foreach (var movie in _movieService.GetTrendingMovies) { // Call the Rating Prediction for each movie prediction prediction = _model.Predict(new MovieRating { userId = id.ToString(), movieId = movie.MovieID.ToString() }); // Normalize the prediction scores for the "ratings" b/w 0 - 100 float normalizedscore = Sigmoid(prediction.Score); // Add the score for recommendation of each movie in the trending movie list ratings.Add((movie.MovieID, normalizedscore)); } //3. Provide rating predictions to the view to be displayed ViewData["watchedmovies"] = WatchedMovies; ViewData["ratings"] = ratings; ViewData["trendingmovies"] = _movieService.GetTrendingMovies; return(View(activeprofile)); }
public void InstanceOk() { MovieRatingPrediction aMovieRatingPrediction = new MovieRatingPrediction(); Assert.IsNotNull(aMovieRatingPrediction); }