ium_464979/IUM_05-predict.py
AWieczarek 8976e3ad75 IUM_06
2024-05-06 19:52:46 +02:00

25 lines
824 B
Python

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')
# 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)