IUM_06
This commit is contained in:
parent
9a77c82ebb
commit
4ee651cb5d
@ -2,31 +2,28 @@ import pandas as pd
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import tensorflow as tf
|
import tensorflow as tf
|
||||||
|
|
||||||
# Load the test data
|
|
||||||
test_data = pd.read_csv('./beer_reviews_test.csv')
|
test_data = pd.read_csv('./beer_reviews_test.csv')
|
||||||
X_test = test_data[['review_aroma', 'review_appearance', 'review_palate', 'review_taste']]
|
X_test = test_data[['review_aroma', 'review_appearance', 'review_palate', 'review_taste']]
|
||||||
y_test = test_data['review_overall']
|
y_test = test_data['review_overall']
|
||||||
|
|
||||||
# Load the model
|
|
||||||
model = tf.keras.models.load_model('beer_review_sentiment_model.h5')
|
model = tf.keras.models.load_model('beer_review_sentiment_model.h5')
|
||||||
|
|
||||||
# Preprocess the test data
|
|
||||||
tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=10000)
|
tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=10000)
|
||||||
tokenizer.fit_on_texts(X_test)
|
|
||||||
X_test_seq = tokenizer.texts_to_sequences(X_test)
|
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)
|
X_test_pad = tf.keras.preprocessing.sequence.pad_sequences(X_test_seq, maxlen=100)
|
||||||
|
|
||||||
# Make predictions
|
|
||||||
predictions = model.predict(X_test_pad)
|
predictions = model.predict(X_test_pad)
|
||||||
print(model.summary())
|
|
||||||
print(f'X_test_pad shape: {X_test_pad.shape}')
|
|
||||||
# Check the shape of the predictions
|
|
||||||
print(f'Predictions shape: {predictions.shape}')
|
print(f'Predictions shape: {predictions.shape}')
|
||||||
|
|
||||||
# If predictions have more than one dimension, select only one dimension
|
|
||||||
if len(predictions.shape) > 1:
|
if len(predictions.shape) > 1:
|
||||||
predictions = predictions[:, 0]
|
predictions = predictions[:, 0]
|
||||||
|
|
||||||
# Save predictions and actual data to a CSV file
|
|
||||||
results = pd.DataFrame({'Predictions': predictions, 'Actual': y_test})
|
results = pd.DataFrame({'Predictions': predictions, 'Actual': y_test})
|
||||||
results.to_csv('beer_review_sentiment_predictions.csv', index=False)
|
results.to_csv('beer_review_sentiment_predictions.csv', index=False)
|
Loading…
Reference in New Issue
Block a user