ium_464979/IUM_05-predict.py
AWieczarek 4ee651cb5d IUM_06
2024-05-06 19:51:16 +02:00

29 lines
895 B
Python

import pandas as pd
import numpy as np
import tensorflow as tf
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']
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)
print(f'Predictions shape: {predictions.shape}')
if len(predictions.shape) > 1:
predictions = predictions[:, 0]
results = pd.DataFrame({'Predictions': predictions, 'Actual': y_test})
results.to_csv('beer_review_sentiment_predictions.csv', index=False)