From 8976e3ad75fcbf53e75b231b553713fab1982aad Mon Sep 17 00:00:00 2001 From: AWieczarek Date: Mon, 6 May 2024 19:52:46 +0200 Subject: [PATCH] IUM_06 --- IUM_05-predict.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/IUM_05-predict.py b/IUM_05-predict.py index 20f65da..d36734e 100644 --- a/IUM_05-predict.py +++ b/IUM_05-predict.py @@ -2,28 +2,24 @@ import pandas as pd import numpy as np import tensorflow as tf +# Load the test data test_data = pd.read_csv('./beer_reviews_test.csv') X_test = test_data[['review_aroma', 'review_appearance', 'review_palate', 'review_taste']] y_test = test_data['review_overall'] +# Load the model model = tf.keras.models.load_model('beer_review_sentiment_model.h5') -tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=10000) - -X_test_list = X_test.values.tolist() - -tokenizer.fit_on_texts(X_test_list) - -X_test_seq = tokenizer.texts_to_sequences(X_test_list) - -X_test_pad = tf.keras.preprocessing.sequence.pad_sequences(X_test_seq, maxlen=100) - -predictions = model.predict(X_test_pad) +# Make predictions +predictions = model.predict(X_test) +# Check the shape of the predictions print(f'Predictions shape: {predictions.shape}') +# If predictions have more than one dimension, select only one dimension if len(predictions.shape) > 1: predictions = predictions[:, 0] +# Save predictions and actual data to a CSV file results = pd.DataFrame({'Predictions': predictions, 'Actual': y_test}) results.to_csv('beer_review_sentiment_predictions.csv', index=False) \ No newline at end of file