public IActionResult Recommend_Restaurant([FromRoute] int id) { var activeuser = _userProfileService.Get_User_details(id); List <(int RestaurantId, float score)> ratings = new List <(int restaurantId, float score)>(); RestaurantPrediction restaurantPrediction = null; List <Restaurant> Best_Restaurants = _restaurantService.GetBestRestaurants; foreach (var restaurant in Best_Restaurants) { // To determine the possible results of visiting the best restaurants generated restaurantPrediction = _machine_model.GetPredictionEngine("Restaurant_Recommendation_Model").Predict(new RestaurantRating { userId = id, restaurantId = restaurant.RestaurantId }); // Using a range of between 1 and 5 to predict the possible results outcome float _score = (float)Math.Round(restaurantPrediction.PredictedRating, 1); // using the _score to create a recommendation for each restaurant in the best restaurant list ratings.Add((restaurant.RestaurantId, _score)); } var results = new List <Restaurant_Recommendation_Results>(); foreach (var item in ratings) { results.Add(new Restaurant_Recommendation_Results() { Restaurant_Name = Best_Restaurants .FirstOrDefault(x => x.RestaurantId == item.RestaurantId).RestaurantName, Restaurant_Type = Best_Restaurants .FirstOrDefault(x => x.RestaurantId == item.RestaurantId).RestaurantType, Restaurant_Rating = item.score }); } return(Ok(results)); }
public void Predict(string inputData) { //1. Akin to what was done in the Trainer class, we verify that the model exists //prior to reading it if (!File.Exists(ModelPath)) { Console.WriteLine($"Failed to find model at {ModelPath}"); return; } //2. Then, we define the ITransformer object //This object will contain our model once we load via the Model.Load method ITransformer mlModel; using (var stream = new FileStream(ModelPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { mlModel = MlContext.Model.Load(stream, out _); } if (mlModel == null) { Console.WriteLine("Failed to load model"); return; } //3. Next, create a PredictionEngine object given the model we loaded earlier PredictionEngine <RestaurantFeedback, RestaurantPrediction> predictionEngine = MlContext.Model.CreatePredictionEngine <RestaurantFeedback, RestaurantPrediction>(mlModel); //4. Then, call the Predict method on the PredictionEngine class RestaurantPrediction prediction = predictionEngine.Predict(new RestaurantFeedback { Text = inputData }); //5. Finally, display the prediction output along with the probability Console.WriteLine($"Based on \"{inputData}\", the feedback is predicted to be:{Environment.NewLine}{(prediction.Prediction ? "Negative" : "Positive")} at a {prediction.Probability:P0} confidence"); }