static void StartManualReviewMode() { RestaurantReviewReader dataReader = new RestaurantReviewReader(); IEnumerable <RestaurantReview> restaurantReviewsTrainingSet = dataReader.LoadRecords("Dataset/Restaurant_Reviews.tsv"); RestaurantReviewClassifier restaurantReviewClassifier = new RestaurantReviewClassifier(restaurantReviewsTrainingSet); while (true) { Console.WriteLine("Type a review:"); string review = Console.ReadLine(); bool isPositive = restaurantReviewClassifier.PredictIsPositiveReview(review); Console.WriteLine("I think this is a " + (isPositive ? "positive" : "negative") + " review"); Console.WriteLine(string.Empty); } }
static void Main(string[] args) { string pathToTrainingData = Path.Combine(Environment.CurrentDirectory, "Data", "Restaurant_Reviews_training.tsv"); string pathToTestData = Path.Combine(Environment.CurrentDirectory, "Data", "Restaurant_Reviews_test.tsv"); RestaurantReviewClassifier restaurantReviewClassifier = new RestaurantReviewClassifier(pathToTrainingData); restaurantReviewClassifier.Evaluate(pathToTestData); SentimentPrediction prediction = restaurantReviewClassifier.Predict(new SentimentData() { SentimentText = "Crust is not good." }); Console.WriteLine(prediction.Prediction); Console.ReadKey(); }
static void PerformBulkTest() { RestaurantReviewReader dataReader = new RestaurantReviewReader(); IEnumerable <RestaurantReview> allRestaurantReviews = dataReader.LoadRecords("Dataset/Restaurant_Reviews.tsv"); IEnumerable <RestaurantReview> trainingSet = allRestaurantReviews.Take(900); IEnumerable <RestaurantReview> testSet = allRestaurantReviews.Skip(trainingSet.Count()); RestaurantReviewClassifier restaurantReviewClassifier = new RestaurantReviewClassifier(trainingSet); foreach (RestaurantReview restaurantReview in testSet) { restaurantReview.Prediction = restaurantReviewClassifier.PredictIsPositiveReview(restaurantReview.Review); } IEnumerable <RestaurantReview> incorrectPrediction = testSet.Where(x => x.Prediction != Convert.ToBoolean(x.IsPositive)); Console.WriteLine($"Number of correct predictions: {testSet.Count() - incorrectPrediction.Count()}"); Console.WriteLine($"Number of incorrect predictions: {incorrectPrediction.Count()}"); Console.Read(); }